位置:C# .NET > C# 提高

c#(asp.net) 计算两个日期之间相隔天数 (时间差)

时间:2013-03-05
简介:C# .NET|1、DateTimet1=Convert.ToDateTime("2006-1-6");DateTimet2=Convert.ToDateTime("2006-1-16");intday=Math.A...
1、
DateTime t1 = Convert.ToDateTime("2006-1-6");
DateTime t2 = Convert.ToDateTime("2006-1-16");
int day=Math.Abs(((TimeSpan)(t1 - t2)).Days);

2、
datediff(day,date1,date2)

3、
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); 

TAGS:c#两个日期隔天数asp.net两个日期隔天数

上一编:asp.net根据网址获取网页页面内容

下一编:C#数据导出到Excel(或Word)源代码大全

NewHot手机版