Reputation: 5902
I have an UWP app for Windows 10 Mobile. The app currently offers two languages - English (en-US
) and Czech (cs-CZ
). The issue I'm having is that when a user for example from Spain uses the app, the date and time formats are American, not Spanish (the default app language is en-US
):
DateTime.Now.ToString("d", System.Globalization.CultureInfo.CurrentCulture);
DateTime.Now.ToString("d", System.Globalization.CultureInfo.CurrentUICulture);
DateTime.Now.ToString(System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern);
I would like to somehow obtain the ACTUAL system language to have the dates and times in the correct format based on the phone language. Currently, it looks like all the APIs from System.Globalization
namespace return the culture info the app is using.
Upvotes: 3
Views: 1936
Reputation: 5902
After more searching, I've managed to come across the following question: Date Time formatting in Windows 10 Universals (Store) Apps where the author of the question mentions the following API call:
Windows.System.UserProfile.GlobalizationPreferences.Languages[0]
This returns the language string for the first language from the user's system preferences language list.
Using it in the following way gives me the expected result:
DateTime.Now.ToString("d", new System.Globalization.CultureInfo(Windows.System.UserProfile.GlobalizationPreferences.Languages[0]));
Upvotes: 3