//DateTime类和TimeSpan类用法实例
using System;
namespace sample3_2DateTime
{
class Program
{
static void Main(string[] args)
{
DateTime dt = new DateTime(2016,10, 25);//使用DateTime类创建一个DateTime对象dt,并赋值2016-10-25
Console.WriteLine(dt.ToShortDateString());//以短日期格式显示出来
Console.WriteLine("2016年10月25日时本年度的地{0}天",dt.DayOfYear);
Console.WriteLine("月份:{0}",dt.Month.ToString());//输出月份值
TimeSpan ts = dt - DateTime.Now;//使用TimeSpan类创建一个TimeSpan对象ts,并赋值,DateTime.Now表示当前日期
Console.WriteLine("今天({0})距离{1}还有{2}天", DateTime.Now, dt.ToShortDateString(), ts.Days.ToString());
Console.ReadKey();
}
}
}