天天看點

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#