I need to show timestamp as shown below in my .Net application:
13/12/2007 5:04 PM EST
or
13/12/2007 5:04 PM CST
depending upon the US timezone.
How do i achieve this functionality using C#??
Thanks for reading.
I need to show timestamp as shown below in my .Net application:
13/12/2007 5:04 PM EST
or
13/12/2007 5:04 PM CST
depending upon the US timezone.
How do i achieve this functionality using C#??
Thanks for reading.
You can just call a DateTime's .ToLongDateString()
method and it will format the result according to the settings on the local system.
Use the DateTime.ToString(string)
method:
DateTime.ToString("dd/MM/yyyy h:mm t K")
This will not match your output format exactly, but it will come close. Since "EST" and "CST" aren't international-friendly, it just displays a divergence from UTC time.
Console.WriteLine(DateTime.Now + " " + TimeZone.CurrentTimeZone.StandardName);
returns
6/10/2009 7:45:14 PM Central Standard Time
TimeZone.CurrentTimeZone.StandardName will return the long name and I believe you will have to modify your code a bit to get the abr. for each zone.