trailblazzyr55
asked on
C# DateTime Formatting based on Locale and Timezone
I'm pretty new to C# and I'm curious how I would format dates and times taking into account locales and timezones.
USA East Coast
---------------------
Example Set: Locale = "en-US", timezone = "America/New_York"
Date Output: April 6, 2010
Time Output: 10:17:59 AM
Full Output: April 6, 2010 10:17:59 AM EDT
Germany
--------------------
Example Set: Locale = "de,GE", timezone = "Europe/Berlin"
Date Output: 6. April 2010
Time Output: 16:17:59
Full Output: 6. April 2010 16:17 Uhr MESZ
In Java I would use java.text.DateFormat and run the following methods...
Date Output: DateFormat.getDateInstance (DateForma t.LONG, locale)
Time Output: DateFormat.getTimeInstance (DateForma t.MEDIUM, locale)
Full Output: DateFormat.getDateTimeInst ance(DateF ormat.LONG , DateFormat.FULL, locale)
Where locale would be an object of java.util.Locale
Then set the timezone: DateFormat.setTimeZone(tim eZone)
Where timezone would be the result of using java.util.TimeZone, calling getTimeZone(String timeZone) and passing it one of the timezones listed above in the example.
Then calling DateFormat.format(Now()) to produce the output above for Date, Time, and Full outputs.
So the output examples above are based on Java and I want to see what the equivalent would be in C# to produce the same results. I don't want to be tied to specifying a particular format other than LONG, MEDIUM, etc... since the format needs to be based on locale.
USA East Coast
---------------------
Example Set: Locale = "en-US", timezone = "America/New_York"
Date Output: April 6, 2010
Time Output: 10:17:59 AM
Full Output: April 6, 2010 10:17:59 AM EDT
Germany
--------------------
Example Set: Locale = "de,GE", timezone = "Europe/Berlin"
Date Output: 6. April 2010
Time Output: 16:17:59
Full Output: 6. April 2010 16:17 Uhr MESZ
In Java I would use java.text.DateFormat and run the following methods...
Date Output: DateFormat.getDateInstance
Time Output: DateFormat.getTimeInstance
Full Output: DateFormat.getDateTimeInst
Where locale would be an object of java.util.Locale
Then set the timezone: DateFormat.setTimeZone(tim
Where timezone would be the result of using java.util.TimeZone, calling getTimeZone(String timeZone) and passing it one of the timezones listed above in the example.
Then calling DateFormat.format(Now()) to produce the output above for Date, Time, and Full outputs.
So the output examples above are based on Java and I want to see what the equivalent would be in C# to produce the same results. I don't want to be tied to specifying a particular format other than LONG, MEDIUM, etc... since the format needs to be based on locale.
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx
ASKER
Thanks for the quick reply, I noticed that link when searching for answers before asking a question here, but I didn't see how they were accounting for the timezone. Is timezone being factored in there?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.