2011年7月12日 星期二

008-倒數計時器

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

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            DateTime startTime = DateTime.Now;
            DateTime endTime = new DateTime(2011, 12, 03, 00, 00, 00);
            TimeSpan myTime = endTime.Subtract(startTime);

            string diffDay = myTime.Days.ToString();
            string diffHour = myTime.Hours.ToString();
            string diffMin = myTime.Minutes.ToString();
            string diffSec = myTime.Seconds.ToString();

            label1.Text = diffDay + "天" + diffHour + "時" + diffMin + "分" + diffSec + "秒";
        }
    }
}