VB difference between windows file hour and VB file hour

时间:2016-04-15 11:00:16

标签: vba date time difference

How to obtain the date from a file without the influence of windows time settings ?

I'm trying to read date file with VB but I obtain a difference between the time writes on file properties (WDT) and the time returns by VB (VBT), due to daylight saving time

If I read a file saved during winter time in summer, I have a difference of VBT = WDT+1h. And in the same case, if I read a file saved during summer in winter, I obtain a difference of VBT = WDT-1h.

1 个答案:

答案 0 :(得分:0)

您需要将DateTime转换为UTC并比较这些次。这是没有任何夏令时调整等的时间。

DateTime类型ToUniversalTime的扩展名返回UTC值:

https://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime(v=vs.110).aspx

示例:

    Dim currentDateTime = DateTime.Now
    Debug.WriteLine(currentDateTime.ToString)
    Debug.WriteLine(currentDateTime.ToUniversalTime.ToString)

我的机器上的输出(英国时区+英国夏令时的UTC时间为1小时)

15/04/2016 12:21:04
15/04/2016 11:21:04

请注意,如果您希望当前系统时间直接以UTC格式

,则还有DateTime.UtcNow