FileTimeToLocalFileTime Function

Declare Function FileTimeToLocalFileTime Lib "kernel32.dll" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long

Platforms: Win32s, Win 95/98, Win NT

FileTimeToLocalFileTime converts a time from UTC time (also known as Greenwich Mean Time) to "local time" (inside the computer's selected time zone). The source and target times are stored in FILETIME structures. The function returns 1 if successful, or 0 if an error occurs.

lpFileTime
The source time and date, which are in UTC time.
lpLocalFileTime
Receives the time and date stored in lpFileTime converted into the computer's current time zone time.

Example:

' Search for all files that match "C:\MyProgram\user*.*".  Display
' the creation time of each file.  Since the file search functions give the file times in UTC
' time, they must be converted to local time before they are displayed.
Dim hsearch As Long  ' handle to the file search
Dim findinfo As WIN32_FIND_DATA  ' receives info about matching files
Dim success As Long  ' will be 1 if successive searches are successful, 0 if not
Dim localtime As FILETIME  ' receives local creation time
Dim systime As SYSTEMTIME  ' receives creation time
Dim retval As Long  ' generic return value

' Begin a file search:
hsearch = FindFirstFile("C:\MyProgram\user*.*", findinfo)
If hsearch = -1 Then  ' no files match the search string
  Debug.Print "(no files matched search parameter)"
  End  ' abort program
End If

' Display creation date of each file that matches the search.  Note that the name
' is displayed, the next file (if any) is found, and then the loop restarts.
' This way the first file (found above) will also be displayed.
Do  ' begin loop
  ' Convert UTC FILETIME to local SYSTEMTIME and display the date:
  retval = FileTimeToLocalFileTime(findinfo.ftCreationTime, localtime)
  retval = FileTimeToSystemTime(localtime, systime)
  Debug.Print "Date:"; systime.wMonth; "-"; systime.wDay; "-"; systime.wYear
  
  ' Get the next matching file and loop if it exists:
  success = FindNextFile(hsearch, findinfo)
Loop Until success = 0  ' keep looping until no more matching files are found

' Close the file search handle
retval = FindClose(hsearch)

See Also: LocalFileTimeToFileTime
Category: Time

Go back to the alphabetical Function listing.
Go back to the Reference section index.


This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/f/filetimetolocalfiletime.html