如何进行两个时间的计算?
假设现在有两个时间变量
dim a as string
dim b as string
a="16:33:20"
b="15:23:12"
问题一:有没有一个涵数能换算出a-b得出的秒数呢?(即答案为:4208秒)
问题二:又有没有一个涵数能换算出a-b得出的时间差呢?(即答案为:"01:10:08")
谢谢!!!
[解决办法]
a="16:33:20"
b="15:23:12"
Dim ta As Long, tb As Long
ta = Val(Split(a, ":")(0)) * 3600 + Val(Split(a, ":")(1)) * 60 + Val(Split(a, ":")(2))
tb = Val(Split(b, ":")(0)) * 3600 + Val(Split(b, ":")(1)) * 60 + Val(Split(b, ":")(2))
MsgBox ta - tb
MsgBox ((ta - tb) \ 3600) & ":" & (((ta - tb) \ 60) Mod 60) & ":" & ((ta - tb) Mod 3600)
[解决办法]
Dim a As Date, b As Date
a = "16:33:20"
b = "15:23:12"
Debug.Print DateDiff("s", b, a)
Debug.Print Format(a - b, "HH:nn:ss")
4208
01:10:08