天天看点

DateTimel类和TimeSpan类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MathClass
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime dt = new DateTime(2018, 3, 27);
            //将对象dt以短日期的格式显示出来
            Console.WriteLine(dt.ToShortDateString());
            Console.WriteLine("2016年3月27日是本年度的第{0}天",dt.DayOfYear);
            //输出对象的月份值
            Console.WriteLine("月份:{0}", dt.Month.ToString());
            TimeSpan ts = dt-DateTime.Now;
            Console.WriteLine("距离现在还有{0}天",ts.Days.ToString());
            Console.ReadKey();
        }
    }
}
           
DateTimel类和TimeSpan类
c#