FileInfo.LastWriteTime doesn't always match Explorer's Last Modified Time.

  • Thread starter Thread starter EMonaco
  • Start date Start date
E

EMonaco

All,

Writing a simple app to list all files in a directory, their size, last
modified date/time, and version number if any. Everything is working great
except double-checking the output to the directory as displayed in explorer,
the time on some files are off by exactly one hour.

To display the time in my app I do strDateTime =
FileInfoObj.LastWriteTime.ToString("g"); Clearly the 1 hour would correspond
to daylight savings. With older files (Jan/04-Mar/04) being the ones that
are off by an hour. Can I correct for this? Basically, I'd like my output to
match explorer, as that was the old method we used to get modified
date/time.


Regards,
Erin.
 
All,

Think I got it:

Instead of the 1 liner I came up with:

System.DateTime dt;

System.TimeZone tz;

dt = fileInfoObj.LastWriteTimeUtc;

tz = System.TimeZone.CurrentTimeZone;

if(!tz.IsDaylightSavingTime(dt))

dt = dt.AddHours(1);

strDateTime = tz.ToLocalTime(dt).ToString("g")

This gives me the same results I see dates I see in explorer. I guess I'd
assumed .ToLocalTime() would take daylight savings in to account. However
that appears not to be the case.


Regards,
Erin.
 
Hi EMonaco,

I am glad you have resolved the problem, if you still have any concern on
this issue, please feel free to let me know.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top