using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QueueSample
{
class Program
{
static void Main(string[] args)
{
DateTime dt1 = new DateTime();
dt1 = DateTime.Parse("2005-5-6 00:00:01");
DateTime dt2 = new DateTime();
dt2 = DateTime.Parse("2005-5-9 23:59:59");
TimeSpan ts = dt2.Subtract(dt1);
Console.WriteLine("相差天数:{0}", ts.TotalDays);
Console.WriteLine("相差小时:{0}", ts.TotalHours);
Console.WriteLine("相差分钟:{0}", ts.TotalMinutes);
Console.WriteLine("相差秒数:{0}", ts.TotalSeconds);
Console.WriteLine("相差豪秒数:{0}", ts.TotalMilliseconds);
//var str = Math.Round((decimal)526.925, 2, MidpointRounding.AwayFromZero);
//Console.WriteLine("526.925四舍五入:{0}", str); //526.93
Console.ReadLine();
}
}
}
C#计算日期之间的差值
本文转载:CSDN博客