自学内容网 自学内容网

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

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


原文地址:https://blog.csdn.net/weixin_53720617/article/details/143487715

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!