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 WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string str = "2009-03-20";//结束的日期
DateTime dt2 = DateTime.Now;//获得今天的日期
DateTime dt1 = Convert.ToDateTime(str);//把结束的日期类型转换为DateTime
string datetime = null;//项目剩余时间
TimeSpan st1 = new TimeSpan(dt1.Ticks);
TimeSpan st2 = new TimeSpan(dt2.Ticks);
TimeSpan ts = st1.Subtract(st2);//结束日期减去当前日期
string dateTerm = ts.Days.ToString() + "天"
+ ts.Hours.ToString() + "小时"
+ ts.Minutes.ToString() + "分钟"
+ ts.Seconds.ToString() + "秒";
datetime = "离项目结束还有" + dateTerm;
label2.Text = datetime;//显示在label里
//MessageBox.Show(dateTerm);
}
}