private void Form1_Load(object sender, EventArgs e) { timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { //要倒數的時間,也可以倒數5秒,例:DateTime MyEndDate = DateTime.Now.AddSeconds(5); DateTime MyEndDate = new DateTime(YY,MM,DD,hh,mm, 0); //取得電腦現在時間 DateTime MyStartDate = DateTime.Now; //執行倒數 TimeSpan MySpan = MyEndDate.Subtract(MyStartDate); string diffDay = Convert.ToString(MySpan.Days); string diffHour = Convert.ToString(MySpan.Hours); string diffMin = Convert.ToString(MySpan.Minutes); string diffSec = Convert.ToString(MySpan.Seconds); //顯示秒數 label1.Text = diffDay + "天" + diffHour + "時" + diffMin + "分" + diffSec + "秒"; }
沒有留言:
張貼留言