http://xiangai.taobao.com
http://shop148612228.taobao.com

C#中求两个日期相差的年月日时分秒

private double DateDiff(string howtocompare, System.DateTime startDate, System.DateTime endDate)
{
double diff=0;
System.TimeSpan TS = new System.TimeSpan(endDate.Ticks-startDate.Ticks);
switch (howtocompare.ToLower())
{
case "year ":
diff = Convert.ToDouble(TS.TotalDays/365);
break;
case "month ":
diff = Convert.ToDouble((TS.TotalDays/365)*12);
break;
case "day ":
diff = Convert.ToDouble(TS.TotalDays);
break;
case "hour ":
diff = Convert.ToDouble(TS.TotalHours);
break;
case "minute ":
diff = Convert.ToDouble(TS.TotalMinutes);
break;
case "second ":
diff = Convert.ToDouble(TS.TotalSeconds);
break;
}
return diff;
}

posted @ 2012-03-02 15:28  万事俱备就差个程序员  阅读(549)  评论(0编辑  收藏  举报

http://xiangai.taobao.com
http://shop148612228.taobao.com
如果您觉得对您有帮助.领个红包吧.谢谢.
支付宝红包
微信打赏 支付宝打赏