I want to find the date a file was created on the users hard drive. I can find it by using API's but it returns the time in UTC. Anyone know how to either convert UTC time or an API that will get the time in a format I can read?
I did write this back to 1~2 monhs time for someone in this forum. Hope it useful for you.
Code:
'//Put this code under a Form
Option Explicit
Private Sub CmdAction_Click()
If optMode(0).Value Then
lblInfo.Caption = GetFileDateTime(txtFile.Text, icCreated)
ElseIf optMode(1).Value Then
lblInfo.Caption = GetFileDateTime(txtFile.Text, icAccessed)
ElseIf optMode(2).Value Then
lblInfo.Caption = GetFileDateTime(txtFile.Text, icModified)
End If
End Sub
Private Sub CmdPath_Click()
On Error GoTo ErrHandle
With CDlg
.DialogTitle = "Open File..."
.ShowOpen
txtFile.Text = .FileName
End With
Exit Sub
ErrHandle:
txtFile.Text = ""
End Sub
'Code improved by vBulletin Tool (Save as...)
'//Put this code under a Basic Module
Option Explicit
'//**********************************************************************
'//This is the Sample Code use to retrieve the given file date time value
'// Author : Chris.C
'// Date : 10, March 2001
'// Email : [email protected]
'// URl : http://go.to/chriscode
'//**********************************************************************
'//WIN32API declare
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFilename As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Long, ByVal " & _
"dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_WRITE = &H2
Private Const FILE_SHARE_READ = &H1
Private Const OPEN_EXISTING = 3
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const FILE_FLAG_RANDOM_ACCESS = &H10000000
'//WIN32API declare
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
'//WIN32API type declare
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private 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
Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Private ft_create As FILETIME
Private ft_last_access As FILETIME
Private ft_last_write As FILETIME
Private st As SYSTEMTIME
Private tz As TIME_ZONE_INFORMATION
Private hFile As Long
Public Enum fDatTime
icCreated = 0
icAccessed = 1
icModified = 2
End Enum