Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

I need the same timestamp that explorer shows for files for any month

I have a problem getting the same timestamp on files created in the months of April and May. I am using Visual Studio 2005 VB .NET 2.0 Framework on an AMD Athlon 64 with Windows XP 64.

I was wondering if you could perform a small test to see if you see what I am getting. Make a small vb form with a label, textbox, and button. Keep the default names for the controls that visual studio gives you. Enter the following code in the button control to be run when it is pushed:

Label1.Text = File.GetLastWriteTime(TextBox1.Text).ToString

You will need to add the following imports statement at the top:

imports System.IO

Could you please run this program on your PC and pick a file that has a lastwrite date in the month of April or May. I found one in my Windows XP 64 Pro Windows directory called hh.exe. In any event, put the full path to the file in the text box and push the button. In my case, any file I pick in the month of April or May will always have one hour added to the display of lastwrite date. Please let me know if you get the same result. I have run this on 3 pc's and they all get the same result, always 1 hour is added to the time for files in the month of April or May. Maybe other months like June and July but I have not tried yet. One hour is not added when you pick files recently created in the last 30 days or so or in this month. Is this a bug in .NET 2.0? Or is there a problem building .NET 2.0 apps on Win xp 64? All I want to do is get the same lastwrite date that is shown in the Windows Explorer but in the case above it always is off by one hour being added to it.
[1661 byte] By [zonkerman] at [2007-11-11 9:52:20]
# 1 Re: I need the same timestamp that explorer shows for files for any month
You must manually adjust the time for daylight savings time:

Dim ModifiedDate as DateTime = File.GetLastWriteTime(txtFileName.Text)
If Not TimeZone.CurrentTimeZone.IsDaylightSavingTime(ModifiedDate) Then
lblModifiedDate = ModifiedDate.AddHours(1).ToString
Else
lblModifiedDate = ModifiedDate.ToString
End If
Phil Weber at 2007-11-11 21:45:19 >