在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
/// <summary> /// 计算时间差值 /// </summary> /// <param name="DateTime1"></param> /// <param name="DateTime2"></param> /// <returns></returns> private string DateDiff(DateTime DateTime1, DateTime DateTime2) { string dateDiff = null; TimeSpan ts1 = new TimeSpan(DateTime1.Ticks); TimeSpan ts2 = new TimeSpan(DateTime2.Ticks); TimeSpan ts = ts1.Subtract(ts2).Duration(); //dateDiff = ts.Days.ToString() + "天" + ts.Hours.ToString() + "小时" + ts.Minutes.ToString() + "分钟" + ts.Seconds.ToString() + "秒"; dateDiff = ts.Days.ToString() + "-" + ts.Hours.ToString(); float nYear = ((float)ts.Days) / 365; //return nYear.ToString(); return dateDiff; } 调用 DateTime dt1 = new DateTime(); DateTime dt2 = new DateTime(); dt1 = DateTime.Now; dt2 = DateTime.Parse("2014-1-2 9:00:00"); MessageBox.Show(DateDiff(dt1,dt2));
|
请发表评论