0

我试图找出两个日期之间的时间跨度。

到目前为止我有什么:

 dim start as DateTime = now
 dim stop as DateTime = now
 dim span as TimeSpan = stop.Subtract(start)

但我没有正确答案。

4

3 回答 3

2

这给出了自 2013 年 1 月 1 日以来经过的时间:

Dim start as DateTime = #1/1/2013#
Dim stop as DateTime = Now
Dim elapsed As TimeSpan = start.Subtract(stop)

Console.Write(elapsed.Days & " days, " & elapsed.Hours & " hours, " & elapsed.Minutes & " minutes, " & elapsed.Seconds & " seconds.")
于 2013-06-12T20:54:30.910 回答
0

在我看来很好。

例如

Dim startTime As DateTime = New DateTime(2013, 6, 12, 22, 45, 0)

Dim endTime As DateTime = New DateTime(2013, 6, 12, 22, 50, 0)

Dim span As TimeSpan = endTime - startTime

结果:00:05:00

于 2013-06-12T20:51:15.200 回答
0

您不能使用"stop""end"作为变量 .. 这应该有效(在 VS2005 上测试)

dim start as DateTime = now
dim stops as DateTime = now
dim span as TimeSpan = stops.Subtract(start)
于 2013-06-12T23:05:14.240 回答