如何通过VBscript计算两个日期时间之间的持续时间
How to calculate Duration of Time between two date time through VBscript
如何通过VBscript计算两个日期时间之间的持续时间
日期 1 = 2021-01-22 11:43:38.000
日期 2 = 2021-01-22 14:32:38.000
结果应该是 HH:MM:SS
我终于回答了我的问题感觉很棒
Date1 = alA_Filling(0)
Date2 = alA_Filling(1)
secValue = DateDiff("s",Date1,Date2)
ts = TimeSerial(0, 0, secValue)
Duration = FormatDateTime(ts, vbLongTime)
但是我得到了类似 2:49:00 AM 的输出,为什么添加 AM 可能是这个 vbLongTime
我怎样才能删除 AM
TimeSerial 和 FormatDateTime return 将计算机的区域设置考虑在内的日期或时间。在我的欧洲计算机上没有显示 AM 扩展名,因为我们使用 24 小时制时间格式。
TimeSerial 的另一个问题是一旦超过 32767 秒就会溢出。
另一种方法可能是分别计算小时、分钟和秒的值。一个可能的解决方案是:
secValue = DateDiff("s",Date1,Date2)
hours = secValue \ 3600
hh = hours
if hours < 10 then
hh = Right("0" & hours, 2)
end if
mm = Right("0" & (secValue - hours * 3600) \ 60, 2)
ss = Right("0" & secValue mod 60, 2)
diff = hh & ":" & mm & ":" & ss
wscript.echo diff
如何通过VBscript计算两个日期时间之间的持续时间
日期 1 = 2021-01-22 11:43:38.000 日期 2 = 2021-01-22 14:32:38.000
结果应该是 HH:MM:SS
我终于回答了我的问题感觉很棒
Date1 = alA_Filling(0)
Date2 = alA_Filling(1)
secValue = DateDiff("s",Date1,Date2)
ts = TimeSerial(0, 0, secValue)
Duration = FormatDateTime(ts, vbLongTime)
但是我得到了类似 2:49:00 AM 的输出,为什么添加 AM 可能是这个 vbLongTime
我怎样才能删除 AM
TimeSerial 和 FormatDateTime return 将计算机的区域设置考虑在内的日期或时间。在我的欧洲计算机上没有显示 AM 扩展名,因为我们使用 24 小时制时间格式。
TimeSerial 的另一个问题是一旦超过 32767 秒就会溢出。
另一种方法可能是分别计算小时、分钟和秒的值。一个可能的解决方案是:
secValue = DateDiff("s",Date1,Date2)
hours = secValue \ 3600
hh = hours
if hours < 10 then
hh = Right("0" & hours, 2)
end if
mm = Right("0" & (secValue - hours * 3600) \ 60, 2)
ss = Right("0" & secValue mod 60, 2)
diff = hh & ":" & mm & ":" & ss
wscript.echo diff