Getting Files LastWriteTime
-
Hi, I need to get the Files last Modified Date.Iam given a Zip File by our client on extracting it I get many files, say I got a File A.txt. whose modified date is 2/19/2008 06:30:00 A.M. Iam using
DateTime \_datetime; String str = "C:\\\\A.txt" FileInfo filinf = new FileInfo(str); \_datetime = filinf.LastWriteTime;
I get the correct output in _datetime. Now , If I change my System TimeZone from ( GMT +5:30)chennai... to (GMT -8:00)Pacific Time (US & Canada) and then again extract the Zip file to get file "A" with modified date as 2/19/2008 06:30:00 A.M and execute the same code I get it as 2/20/2008 05:30:00 A.M. Why is it So?There is an offset of 1 hour. I need Files Last Modified Date(say here 2/19/2008 06:30:00 A.M only) Irrespective of TimeZones Iam In. Any suggestions would be appreciated. Thanks Satya
Today is a gift, that's why it is called the present.
-
Hi, I need to get the Files last Modified Date.Iam given a Zip File by our client on extracting it I get many files, say I got a File A.txt. whose modified date is 2/19/2008 06:30:00 A.M. Iam using
DateTime \_datetime; String str = "C:\\\\A.txt" FileInfo filinf = new FileInfo(str); \_datetime = filinf.LastWriteTime;
I get the correct output in _datetime. Now , If I change my System TimeZone from ( GMT +5:30)chennai... to (GMT -8:00)Pacific Time (US & Canada) and then again extract the Zip file to get file "A" with modified date as 2/19/2008 06:30:00 A.M and execute the same code I get it as 2/20/2008 05:30:00 A.M. Why is it So?There is an offset of 1 hour. I need Files Last Modified Date(say here 2/19/2008 06:30:00 A.M only) Irrespective of TimeZones Iam In. Any suggestions would be appreciated. Thanks Satya
Today is a gift, that's why it is called the present.
I think you should use Globalization For that. User RegionInfo Class and Try to use the date time from that class. This is just my idea !!!
Best Regards ----------------- Abhijit Jana Microsoft Certified Professional "Success is Journey it's not a destination"
-
Hi, I need to get the Files last Modified Date.Iam given a Zip File by our client on extracting it I get many files, say I got a File A.txt. whose modified date is 2/19/2008 06:30:00 A.M. Iam using
DateTime \_datetime; String str = "C:\\\\A.txt" FileInfo filinf = new FileInfo(str); \_datetime = filinf.LastWriteTime;
I get the correct output in _datetime. Now , If I change my System TimeZone from ( GMT +5:30)chennai... to (GMT -8:00)Pacific Time (US & Canada) and then again extract the Zip file to get file "A" with modified date as 2/19/2008 06:30:00 A.M and execute the same code I get it as 2/20/2008 05:30:00 A.M. Why is it So?There is an offset of 1 hour. I need Files Last Modified Date(say here 2/19/2008 06:30:00 A.M only) Irrespective of TimeZones Iam In. Any suggestions would be appreciated. Thanks Satya
Today is a gift, that's why it is called the present.
I got the solution
FileInfo filinf = new FileInfo(FileName);
_datetime = filinf.LastWriteTime;DaylightTime dlt = TimeZone.CurrentTimeZone.GetDaylightChanges(_datetime.Year);
//String strHrs = dlt.Delta.Hours.ToString();
_datetime = _datetime.AddHours(Convert.ToDouble(dlt.Delta.Hours));
_datetime = _datetime.AddMinutes(Convert.ToDouble(dlt.Delta.Minutes));
_datetime = _datetime.AddSeconds(Convert.ToDouble(dlt.Delta.Seconds));Thanks
Today is a gift, that's why it is called the present.
-
I got the solution
FileInfo filinf = new FileInfo(FileName);
_datetime = filinf.LastWriteTime;DaylightTime dlt = TimeZone.CurrentTimeZone.GetDaylightChanges(_datetime.Year);
//String strHrs = dlt.Delta.Hours.ToString();
_datetime = _datetime.AddHours(Convert.ToDouble(dlt.Delta.Hours));
_datetime = _datetime.AddMinutes(Convert.ToDouble(dlt.Delta.Minutes));
_datetime = _datetime.AddSeconds(Convert.ToDouble(dlt.Delta.Seconds));Thanks
Today is a gift, that's why it is called the present.
Hi, you have a problem with FileInfo.LastWriteTime? if you read the documentation, you should notice the very next item in MSDN is FileSystemInfo.LastWriteTimeUtc :)
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.
-
Hi, I need to get the Files last Modified Date.Iam given a Zip File by our client on extracting it I get many files, say I got a File A.txt. whose modified date is 2/19/2008 06:30:00 A.M. Iam using
DateTime \_datetime; String str = "C:\\\\A.txt" FileInfo filinf = new FileInfo(str); \_datetime = filinf.LastWriteTime;
I get the correct output in _datetime. Now , If I change my System TimeZone from ( GMT +5:30)chennai... to (GMT -8:00)Pacific Time (US & Canada) and then again extract the Zip file to get file "A" with modified date as 2/19/2008 06:30:00 A.M and execute the same code I get it as 2/20/2008 05:30:00 A.M. Why is it So?There is an offset of 1 hour. I need Files Last Modified Date(say here 2/19/2008 06:30:00 A.M only) Irrespective of TimeZones Iam In. Any suggestions would be appreciated. Thanks Satya
Today is a gift, that's why it is called the present.
Use
LastWriteTime**Utc**
instead. TheLastWriteTime
property is adjusted for timezone and daylight savings time, while the UTC version is not.A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008