views:

518

answers:

3

Is there any windows API or language feature (C++,C#) to get the time, date and time zone name in localized format for different languages?

EDIT: In C# I can get the localized strings for date and time, but it seems TimeZoneInfo doesn't have localized strings. I also didn't find it in the registry. Most probably you need to translate timezone names for yourself.

// Localize date for french
DateTime d = new DateTime.Now;
Console.WriteLine(d.ToString("D", new CultureInfo("fr-FR")));
A: 

boost date_time localizations to the rescue.

Hassan Syed
This apparently requires you to do the localization yourself. Which is kind of unnecessary, given that the OS already has a set of localized strings somewhere.
Joey
It's portable and easily extendible -- if you feel that it is appropriate to lock yourself in to Microsoft's translations, feel free. Besides, I'm sure you can find a list of pre-rolled localizations.
Hassan Syed
+2  A: 

See the GetTimeFormat, GetDateFormat, and GetTimeZoneInformation functions. To get the localized name for the time zone, it seems like you might need to pull it out of the registry. See the documentation for the TIME_ZONE_INFORMATION structure.

jamesdlin
You don't need to go to the registery, there is a call which configures the correct system localization formating (just a heads up -- you should be able to find it on MSDN, I don't remember the call off the top of my head).
Hassan Syed
A: 

Since at least XP SP3, the Win32 API GetTimeZoneInformation produces names which are localized. In fact, the reason I found this question was that I would like a way to force these strings into English because I'm putting them in a debugging log and I'd like to be able to understand them without becoming fluent in all the world's natural languages. :-)

Integer Poet
Did you manage somehow to force it to english? It would be part of the solution for my question.
Andras
I decided to skip that after realizing that the bias field is the critical piece of information for my case. The zone name is just window dressing for my case because the actual zones are a politicized mess.
Integer Poet