UserAccountInfo时间倒计时

界面如下:

代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;

namespace WeChatTool
{
public partial class UserAccountInfo : UserControl
{
private TimeSpan timespan = new TimeSpan(2, 0, 0);
private double startTime;
System.Timers.Timer timer = new System.Timers.Timer();
public UserAccountInfo()
{
InitializeComponent();
timer.Enabled = true;
timer.Interval = 1000;
timer.Stop();
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_tick);
}

private void UserAccountInfo_Load(object sender, EventArgs e)
{

}

private void btnProduceToken_Click(object sender, EventArgs e)
{
string token = "";
try
{
Uri url = new Uri("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx04ec9a465d7bbaf2&secret=a31fbf89aa42f984bb3f13a8bf5db949");
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "GET";//默认方法是GET
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream, Encoding.UTF8);
token = reader.ReadToEnd();
this.rtbToken.Text = token;
Properties.Settings.Default.token = token;
startTime = timespan.TotalSeconds;
timer.Start();

}
catch (ProtocolViolationException ex)
{
MessageBox.Show("使用网络协议期间出错时引发的异常! " + ex.ToString(), "提示信息!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
//throw;
}
}

private void btnRefresh_Click(object sender, EventArgs e)
{
this.timer.Stop();
this.btnTimer.Text = null;
}

private void timer_tick(object sender, System.Timers.ElapsedEventArgs e)
{
setTimer(startTime);
}

public delegate void SetTimer(double timer);

private void setTimer(double timer)
{
if (this.InvokeRequired)
{
this.Invoke(new SetTimer(setTimer), timer);
}
else
{
DateTime datetime = new DateTime(2016,8,18,(int)(timer/3600),(int)((timer/60)%60),(int)((timer/1)%60));
this.btnTimer.Text = datetime.ToString();
startTime -= 1;
}
}

}
}

时间: 2024-08-10 10:14:49

UserAccountInfo时间倒计时的相关文章

时间倒计时

JavaScript中的Date日期对象 Date()返回当前日期和时间 getDate()查看Date对象并返回日期(1-31) getDay()返回星期几(0-6) getHours()返回小时数(0-23) getMinutes()返回分钟数(0-59) getMonth()返回月份值(从0开始,+1) getSeconds() 返回秒数 getTime() getYear() getFullYear() 时间倒计时代码如下: <!DOCTYPE HTML><html><

指定时间倒计时

<!doctype html><html><head> <meta charset="utf-8"> <title>指定时间倒计时</title></head><body><DIV id="CountMsg" class="HotDate"> <span id="t_d">00天</span> &

JavaScript 倒计时(截止某日期的倒计时和截止每晚12点的倒计时以及固定时间倒计时)

截止某日期的倒计时和截止每晚12点倒计时: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> </head> <body> <h1 id="divTime"></h1> </body> <script type="text/javascript&qu

原生js 当前时间 倒计时代码

源:https://www.oschina.net/code/snippet_2318153_54763 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>原生js 当前时间 倒计时代码</ti

JS时间倒计时

<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf8" /><title>JS时间倒计时</title><script type="text/javascript">var time_

ecshop促销时间倒计时效果

ecshop促销时间倒计时效果的实现如下: 1.首先修改程序部分 打开includes/lib_goods.php 找到get_promote_goods()函数部分 在 $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); 下面增加代码 $time = gmtime(); if ($time >= $row['promote_start_date'] &a

SharePoint 时间倒计时源码共享

今天老板让我们用SharePoint做了一个时间倒计时的插件,主要功能就是,手动输入你想查询的节日,然后输入日期,得出一个该节日的倒计时结果. 下面是主要代码内容: 第一个SharePoint成品,写的不好还望大家多多包含.如果有什么意见或建议还请给位大神提出来,以便于我的提高.

js时间倒计时---摘抄别人的--收藏

/*时间倒计时插件TimeDown.js*/function TimeDown(id, endDateStr) { //结束时间 var endDate = new Date(endDateStr); //当前时间 var nowDate = new Date(); //相差的总秒数 var totalSeconds = parseInt((endDate - nowDate) / 1000); //天数 var days = Math.floor(totalSeconds / (60 * 60

php 时间倒计时

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-