
网页版的要用JS。传入一个服务器时间做种子。没现成的函数可用了。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
System.Timers.Timer tm = new System.Timers.Timer();
tm.Enabled = true;
tm.Interval = 1000;
tm.Elapsed += ReminderEvent;
}
delegate void StringDele(string strText);
DateTime dtTarget = new DateTime(2018, 9, 27);
private void ReminderEvent(object sender, System.Timers.ElapsedEventArgs e)
{
var duration = dtTarget.Subtract(DateTime.Now);
this.label1.Invoke(new StringDele((x) => { this.label1.Text = x; }),
"距离我2018年生日还有:"+duration.Days + "天" + duration.Hours
+ "时" + duration.Minutes + "分" + duration.Seconds + "秒");
}
}