简体   繁体   中英

Different timestamps under winXP, win7 and vb.net

Within a VB.net program I used IO.File.GetCreationTime to read the file system's creation time of a file. I was irritated, because the returned value didn't match with the time displayed in the explorer. On another machine the time was displayed correctly.

  • Both machines use NTFS
  • I copied the file from a read-only FAT32 USB-drive to the desktop of each machine
  • Both machines are using the same time zone (GMT+1 plus DST)

timestamps displayed:

  • my VB.net app (both machines) - 21:09
  • Explorer time Windows XP - 22:09
  • Explorer time Windows 7 - 21:09
  • (MacOS X - 21:09)

The good thing is, that the file I'm talking about is a PDF file. According to the PDF's meta information the file was created on 03. Jan. 2002 22:09

I want that the file system dates are the same on every machine. How would you solve this problem using VB.net?

I used a simple app to summarize the timestamp information:

GetLastWriteTime(file)
GetLastWriteTimeUtc(file)
GetLastWriteTime(file).ToLocalTime
GetLastWriteTimeUtc(file).ToLocalTime
GetLastWriteTime(file).ToFileTime
GetLastWriteTimeUtc(file).ToFileTime

Date.Now
Date.Now.UtcNow

The output was the same on both machines. For some reason I changed the time zone settings on both machines, switching DST on and off. The result is interesting ...

  • ... when you turn off DST on Windows XP all time stamps are reduced by one (because during DST my time zone is GMT+2 (now) , during the wintertime it is GMT+1)
  • ... on a Windows 7 machine only files created during DST (GMT+2) are affected by this (my file was created in January)

I guess it's the same effect vice versa. So my problem is just a disply issue. To solve this I will only use the UTC-Functions and care about DST within my app. So there still will be an offset, but it should be ok as long as it is just a display issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM