有人可以帮我做这个工作吗?
我想在VB.NET中计算两个日期之间的时间,如下所示:
startdate: 2011/12/30 enddate: 2011/12/31
计算: ?小时?一分钟?秒
你可以试试这个
原文链接:https://www.f2er.com/vb/255466.htmlDateTime startTime = DateTime.Now; DateTime endTime = DateTime.Now.AddSeconds( 75 ); TimeSpan span = endTime.Subtract ( startTime ); Console.WriteLine( "Time Difference (seconds): " + span.Seconds ); Console.WriteLine( "Time Difference (minutes): " + span.Minutes ); Console.WriteLine( "Time Difference (hours): " + span.Hours ); Console.WriteLine( "Time Difference (days): " + span.Days );
输出像,
Time Difference (seconds): 15 Time Difference (minutes): 1 Time Difference (hours): 0 Time Difference (days): 0
而VB.Net相当于上面的内容:
Dim startTime As DateTime = DateTime.Now Dim endTime As DateTime = DateTime.Now.AddSeconds(75) Dim span As TimeSpan = endTime.Subtract(startTime) Console.WriteLine("Time Difference (seconds): " + span.Seconds) Console.WriteLine("Time Difference (minutes): " + span.Minutes) Console.WriteLine("Time Difference (hours): " + span.Hours) Console.WriteLine("Time Difference (days): " + span.Days)