Reputation: 2393
I'm using LastWriteTime
property for a file which I use, to print the last modified time.
However, here when I use I get a value like
"2/12/2011 11:58:45 AM".
(i) Can you pls help to ignore seconds here meaning the output should be like: 2/12/2011 11:58 AM
(ii) Also, how do I ensure that I'm taking care of time zones as in the file LastWriteTime could be as per other GEO timings. Can you pls help to take care of this?
(iii) Also how to take care of Culture problems here as CurrentCulture would be different for machines?
Upvotes: 3
Views: 614
Reputation: 5007
The patterns for DateTime.ToString ( 'g' ) :
0 MM/dd/yyyy HH:mm 08/22/2006 06:30
1 MM/dd/yyyy hh:mm tt 08/22/2006 06:30 AM
2 MM/dd/yyyy H:mm 08/22/2006 6:30
3 MM/dd/yyyy h:mm tt 08/22/2006 6:30 AM
Source: DateTime.ToString Patterns
Upvotes: 4
Reputation: 12786
You can use the g
format to represent the date as you wish:
string date = File.GetLastWriteTime("file").ToString("g");
As for the TimeZone
, DateTime
doesn't contain relevant TimeZone
information. You'll have to handle this yourself.
Maybe this will help you: http://hashfactor.wordpress.com/2009/02/02/c-parsing-datetime-with-timezone/
Upvotes: 1