btcq.net
当前位置:首页 >> C# 时间差 >>

C# 时间差

两个时间相减就行了,得到的是一个TimeSpan类 TimeSpan ts = dt1-dt1; ts.TotalMinutes...

你用下面这些代码试下: DateTime d1=DateTime.Parse(strFsi.Insert(4,"-")); //把你读到的转换成时间类型或者 DateTime d1=DateTime.ParseExact(strFsi, "yyyyMM", null); int mm =(int)((TimeSpan)DateTime.UtcNow.Subtract(d1)).TotalMinutes...

TimeSpan span = Convert.ToDateTime("2014-09-26").Subtract(Convert.ToDateTime("2014-09-27")); span.TotalDays;//天 span.TotalHours;//小时 span.TotalMinutes;//分钟 span.TotalSeconds;//秒

DateTime dt1 = Convert.ToDateTime(d1); DateTime dt2 = Convert.ToDateTime(d2); TimeSpan ts = dt1 - dt2; int sub = ts.Days; //sub就是两天相差的天数

1.直接在数据库中读的时候算时间: datediff(hour,'2008-08-08 10:10:10','2008-08-08 12:34:56')

DateTime dt1 = new DateTime(2016, 02, 01); DateTime dt2 = new DateTime(2016, 03, 01); TimeSpan days = dt1.Subtract(dt2); Console.WriteLine(days.Days);

DateTime dt1 = Convert.ToDateTime("2010-10-1 10:01:30"); DateTime dt2 = Convert.ToDateTime("2010-10-2 10:02:40"); TimeSpan ts = dt2.Subtract(dt1); Console.WriteLine(ts.TotalSeconds);

int dminute = (new DateTime(年, 月, 日) - new DateTime(年, 月, 日)).Minutes;

private int Fun(DateTime datetime) { DateTime dt = DateTime.Now; DateTime dt2 = datetime; if (DateTime.Compare(dt, dt2) 14) { month++; } return month; }

TimeSpan span = date1 - date2; int n=span.Minutes;

网站首页 | 网站地图
All rights reserved Powered by www.btcq.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com