vb.net – 计算两个日期之间的时间?

前端之家收集整理的这篇文章主要介绍了vb.net – 计算两个日期之间的时间?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有人可以帮我做这个工作吗?

我想在VB.NET中计算两个日期之间的时间,如下所示:

startdate: 2011/12/30  
enddate: 2011/12/31

计算: ?小时?一分钟?秒

你可以试试这个
DateTime 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)
原文链接:https://www.f2er.com/vb/255466.html

猜你在找的VB相关文章