CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2000
    Location
    Netherlands
    Posts
    71

    File Date/Time and Time Zones

    Hi,

    We have a huge problem and can not find any information on this on the TechNet and MSDN site of Microsoft.

    When we look up the creation date/time from a file, it returns a specific time, e.g. 15:05. But when the time zone changes, the time is changed to 16:05. This all happens on the server running Windows NT4.0 SP6a, file opened from a DOS box. Since we want the original date and time this is not what we want to see, we use this as a sort of copy protection.

    But wait, there's more. When we do the same from a mapped network drive on a Windows 2000 Pro station with the same time zone and locale settings, we get 18:05 as the file creation time!!! And to make it even worse, from a Windows 98 SE with the same time zone and locale settings we get 17:05 as the file creation time!!!
    But when we use a NET USE TIME \\server command all times are changed again, while are times where equal to the servers time. From all stations the time is set to 16:05, just like on the server.

    Now this has become a complete blur. When we set the correct time zones (and we checked dates and times from the time zone information) file times differ from OS to OS and are synced when we sync the time to the servers time.

    HOW COME!!!!! AAAAAARRRRRRGGGGGHHHHHHH!!!!!


    Jeroen.


  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: File Date/Time and Time Zones

    From the way I gather it, The files data and times are stored in GMT time and the retrieving systems GMT offset comes into play here.
    There are more than several API's that deal with file Date and Times. Here are several I know of

    option Explicit

    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

    Dim hfile as Integer
    Dim FileStruct as OFSTRUCT
    Dim iRC as Integer
    Dim CreationTime as FILETIME
    Dim LastAccessTime as FILETIME
    Dim LastWriteTime as FILETIME
    Dim SYSTIME as SYSTEMTIME
    Dim LocalTime as FILETIME
    Dim s$, dl&

    private Declare Function FileTimeToLocalFileTime& Lib "kernel32" _
    (lpFileTime as FILETIME, lpLocalFileTime as FILETIME)
    private Declare Function GetTimeFormat& Lib "kernel32" Alias "GetTimeFormatA" _
    (byval Locale as Long, byval dwFlags as Long, lpTime as SYSTEMTIME, _
    byval lpFormat as Long, byval lpTimeStr as string, byval cchTime as Long)
    private Declare Function FileTimeToSystemTime Lib "kernel32" _
    (lpFileTime as FILETIME, lpSystemTime as SYSTEMTIME) as Long
    private Declare Function GetFileTime Lib "kernel32" (byval _
    hfile as Long, lpCreationTime as FILETIME, lpLastAccessTime _
    as FILETIME, lpLastWriteTime as FILETIME) as Long
    private Declare Function OpenFile Lib "kernel32" (byval lpFileName as _
    string, lpReOpenBuff as OFSTRUCT, byval wStyle as Long) as Long
    private Declare Function hread Lib "kernel32" Alias "_hread" _
    (byval hfile as Long, lpBuffer as Any, byval lBytes as Long) as Long
    private Declare Function lclose Lib "kernel32" Alias "_lclose" (byval _
    hfile as Long) as Long

    ' Also from another sample I have
    #If Win32 then

    private Declare Function GetTimeFormat& Lib "kernel32" Alias "GetTimeFormatA" (byval Locale as Long, byval dwFlags as Long, lpTime as SYSTEMTIME, byval lpFormat as Long, byval lpTimeStr as string, byval cchTime as Long)
    private Declare Function GetDateFormat& Lib "kernel32" Alias "GetDateFormatA" (byval Locale as Long, byval dwFlags as Long, lpTime as SYSTEMTIME, byval lpFormat as Long, byval lpTimeStr as string, byval cchTime as Long)
    private Declare Function FileTimeToSystemTime& Lib "kernel32" (lpFileTime as FILETIME, lpSystemTime as SYSTEMTIME)
    private Declare Function GetFileInformationByHandle& Lib "kernel32" (byval hFile as Long, lpFileInformation as BY_HANDLE_FILE_INFORMATION)
    private Declare Function CloseHandle& Lib "kernel32" (byval hObject as Long)

    #End If 'WIN32







    '
    I suppose all are documented on MSDN.Microsoft.com
    If you are interested in a couple of samples, Send me a private message with your E-Mail address and I will send them to you. They are to large to post here


    John G

  3. #3
    Join Date
    Oct 2000
    Location
    Netherlands
    Posts
    71

    Re: File Date/Time and Time Zones

    This goes beyond the local workstations:
    - Each file saved on the server gets the time from the local workstation
    - One hour is added (!!!) instead of subtracted to get the GMT time, this is done by either the workstation or the server
    - The file is stored on the server
    - When the file is retrieved again one hour is added to the file date/time

    Now please explain this behaviour. We've tested this on three independent servers running Windows NT 4.0 SP6a.

    Due to this behaviour the GMT time set on the file is also incorrect, even when checking using API's...


    Jeroen.


  4. #4
    Join Date
    May 2006
    Posts
    4

    Re: File Date/Time and Time Zones

    I know this is long ago, but I did run into the same problem now!! Did you manage to find a solution for it????

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: File Date/Time and Time Zones

    It's posted. Are you running NT and Windows 98 like the original poster was (and which has already helped quite a few people)

    If you have the *exact* same problem, then we'll help, otherwise, start your own thread, please.

    (Doesn't sound like a VB6 problem anyways)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured