本文介绍了计算两次之间的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好 我想写一个方法; 一开始开始时间 2次结束时间 3-计算它们之间的时间 也用于日期: 一开始获取日期 2次获取结束日期 3-计算它们之间的日期 请大家帮忙,谢谢大家.
Hello All i want to write a method; 1-get start time 2-get end time 3-calculate time between them also for date: 1-get start date 2-get end date 3-calculate date between them please help,thanks everyone
推荐答案根据需要进行修改. Modify as required. // Times DateTime time1 = DateTime.Parse("22:00"); DateTime time2 = DateTime.Parse("23:45"); TimeSpan timeDiff = time2 - time1; Console.WriteLine("There are " + timeDiff.Minutes + " minutes between the two times."); // Dates DateTime date1 = DateTime.Parse("17 March 2012"); DateTime date2 = DateTime.Parse("14 June 2012"); TimeSpan dateDiff = date2 - date1; Console.WriteLine("There are " + dateDiff.Days + " days between the two dates."); Console.ReadLine();
请参阅 TimeSpan类 [ ^ ]用于增量时间和日期时间类 [ ^ ]绝对时间. 干杯 Andi See TimeSpan Class[^] for delta times and DateTime Class[^] for absolute times. Cheers Andi
请检查以下示例. Please check the below example. static void Main(string[] args) { DateTime tm1 = DateTime.Parse("05:35"); DateTime tm2 = DateTime.Parse("13:57"); TimeSpan ts = (tm2 - tm1); Console.WriteLine(ts); DateTime dt1= DateTime.Parse("5/12/2012"); DateTime dt2 = DateTime.Parse("7/12/2012"); int days = (dt2 - dt1).Days; Console.WriteLine(days); Console.Read(); }
这将返回u 08:22(时差) 2(日期差异)
This will return u 08:22(time diff) 2(date diff)
更多推荐
计算两次之间的时间
发布评论