VBA 脚本 FileSystemObject 返回不同的时间
VBA Scipting FileSystemObject returning different time
我在返回文件的创建日期时遇到问题,如下所示:
Set fsoFile = CreateObject("Scripting.FileSystemObject")
Set File = fsoFile.GetFile([Path] & [Filename])
debug.print File.DateCreated
它返回的时间比 windows 资源管理器上显示的时间早一个小时?
不知道系统时间有没有改过,有没有一段时间系统时间不对,现在肯定是对的。
有人知道这会是什么吗be/had 类似的问题?
谢谢
难道你在欧洲?
官方文档FILETIME structure指出,NTFS将文件日期存储为UTC时间,因此(目前)一个比当地时间慢一小时。
您可以通过以下方式找到当前的 UTC 时间:
Public Type SystemTime
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
' Returns the current UTC time.
Private Declare PtrSafe Sub GetSystemTime Lib "kernel32" ( _
ByRef lpSystemTime As SystemTime)
' Retrieves the current date and time from the local computer as UTC.
' By cutting off the milliseconds, the resolution is one second to mimic Now().
'
' 2016-06-09. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function UtcNow() As Date
Dim SysTime As SystemTime
Dim Datetime As Date
' Retrieve current UTC date/time.
GetSystemTime SysTime
Datetime = _
DateSerial(SysTime.wYear, SysTime.wMonth, SysTime.wDay) + _
TimeSerial(SysTime.wHour, SysTime.wMinute, SysTime.wSecond)
UtcNow = Datetime
End Function
然后使用 DateDiff("n", UtcNow, Now) 找出 UTC 时间和本地时间之间的差异,然后将其添加到检索到的文件时间中。
我在返回文件的创建日期时遇到问题,如下所示:
Set fsoFile = CreateObject("Scripting.FileSystemObject")
Set File = fsoFile.GetFile([Path] & [Filename])
debug.print File.DateCreated
它返回的时间比 windows 资源管理器上显示的时间早一个小时?
不知道系统时间有没有改过,有没有一段时间系统时间不对,现在肯定是对的。
有人知道这会是什么吗be/had 类似的问题?
谢谢
难道你在欧洲?
官方文档FILETIME structure指出,NTFS将文件日期存储为UTC时间,因此(目前)一个比当地时间慢一小时。
您可以通过以下方式找到当前的 UTC 时间:
Public Type SystemTime
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
' Returns the current UTC time.
Private Declare PtrSafe Sub GetSystemTime Lib "kernel32" ( _
ByRef lpSystemTime As SystemTime)
' Retrieves the current date and time from the local computer as UTC.
' By cutting off the milliseconds, the resolution is one second to mimic Now().
'
' 2016-06-09. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function UtcNow() As Date
Dim SysTime As SystemTime
Dim Datetime As Date
' Retrieve current UTC date/time.
GetSystemTime SysTime
Datetime = _
DateSerial(SysTime.wYear, SysTime.wMonth, SysTime.wDay) + _
TimeSerial(SysTime.wHour, SysTime.wMinute, SysTime.wSecond)
UtcNow = Datetime
End Function
然后使用 DateDiff("n", UtcNow, Now) 找出 UTC 时间和本地时间之间的差异,然后将其添加到检索到的文件时间中。