Get localized date time string and time zone name in differnet languages on windows [duplicate]
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")));
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.
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. :-)
boost date_time localizations to the rescue.
精彩评论