见MSDN:
代码:确定两个日期之间的间隔 (Visual C#)
本示例计算两个日期之间相差的天数并为该差额构造一个 TimeSpan 值。
示例
DateTime oldDate = new DateTime(2002,7,15);
DateTime newDate = DateTime.Now;
// Difference in days, hours, and minutes.
TimeSpan ts = newDate - oldDate;
// Difference in days.
int differenceInDays = ts.Days;
Console.WriteLine( "Difference in days: {0} ", differenceInDays);
编译代码
代码:确定两个日期之间的间隔 (Visual C#)
本示例计算两个日期之间相差的天数并为该差额构造一个 TimeSpan 值。
示例
DateTime oldDate = new DateTime(2002,7,15);
DateTime newDate = DateTime.Now;
// Difference in days, hours, and minutes.
TimeSpan ts = newDate - oldDate;
// Difference in days.
int differenceInDays = ts.Days;
Console.WriteLine( "Difference in days: {0} ", differenceInDays);
编译代码
复制该代码,并将其粘贴到控制台应用程序的 Main 方法中。
本文转自左正博客园博客,原文链接:http://www.cnblogs.com/soundcode/archive/2012/02/02/2336052.html,如需转载请自行联系原作者