2

I need to get the current time format in a WinRT app using c#. I have used GeographicRegion to get the region, it will just tell us the location not the format. But normally we just change the format to change the system's date time format.

So help me to find how we exactly know the format, as its always returning me the "en-US" (the default language).

Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
Mandeep Kaur
  • 183
  • 4
  • 17
  • Isn't the Locale *specified* by the user? In any case, see http://stackoverflow.com/questions/12560412/winrt-apps-and-regional-settings-the-correct-way-to-format-dates-and-numbers-ba perhaps –  Jan 30 '13 at 07:09
  • Yes, the locale can be specified by the user....but the app's requirement is to change some strings to the changed culture, to do this I need to check when the format has changed in the running app or at least at the app startup. – Mandeep Kaur Jan 30 '13 at 07:14

2 Answers2

0

This shows how you can get the long time pattern (format) for the current UI culture, the specified (Polish) culture, get the current time with default format for the specified culture and with the specified pattern:

Debug.WriteLine(CultureInfo.CurrentUICulture.DateTimeFormat.LongTimePattern);
Debug.WriteLine(new CultureInfo("pl-pl").DateTimeFormat.LongTimePattern);
Debug.WriteLine(DateTime.Now.ToString(new CultureInfo("pl-pl")));
Debug.WriteLine(DateTime.Now.ToString(new CultureInfo("pl-pl").DateTimeFormat.ShortTimePattern));

And these are the outputs:

H:mm:ss
HH:mm:ss
2013-01-30 08:21:09
08:21
Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
  • Thanks Filip, But I want to know the event or a property which will tell me the current culture (in the running app or at least at the app start up) so that I can change the strings. Like in your answer, how should I find that it is the "pl-pl" culture not the "en-US".... – Mandeep Kaur Jan 31 '13 at 11:30
  • I did mention CultureInfo.CurrentUICulture... There is also CultureInfo.CurrentCulture – Filip Skakun Jan 31 '13 at 14:33
  • No, its not giving the exact culture it is always returning the "en-US"(the default language of app) culture in Metro app, I have used it in WPF project there it is giving the right culture but in Metro app it always gives the same. – Mandeep Kaur Feb 01 '13 at 06:18
0

The top language in Windows.Globalization.ApplicationLanguages.Languages tells you the language the application is running in.

You don't have to get that though, those languages are the default when you construct a Windows.Globalization.DateTimeFormatter and don't provide languages.

If you want to know what the format is without actually rendering a specific time, use the Patterns property.

Eric MSFT
  • 3,246
  • 1
  • 18
  • 28