tags:

views:

401

answers:

4

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.

+4  A: 

You can just call a DateTime's .ToLongDateString() method and it will format the result according to the settings on the local system.

Joel Coehoorn
+1  A: 

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.

Lee
+5  A: 
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.

JTA
thanks a ton James..!
Steve Chapman
No problem, glad to help.
JTA
A: 

Hello Here is your solotion

    private string ShortTimeZone(string timeZoneFormat)
    {
        string[] TimeZoneElements = timeZoneFormat.Split(' ');
        string shortTimeZone = String.Empty;

        foreach (string element in TimeZoneElements)
        {
            shortTimeZone += element[0];
        }

        return shortTimeZone;
    }