尊重 Windows Store 应用中的用户日期时间格式设置
Respect users date time format settings in Windows Store app
在 Windows Store 应用程序(8.1,非 UWP)中,如何获取 Windows 10 中配置的日期和时间格式?在以下示例中,安装的操作系统语言为 en-US
,时间和货币格式设置为 de-DE
.
我试过了:
new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shortdate"); // resolved language = en-US, resolved geographic region = ZZ ?!
Windows.Globalization.Language.CurrentInputMethodLanguageTag; // en-US
Windows.System.UserProfile.GlobalizationPreferences.Languages; // en-US
Windows.Globalization.ApplicationLanguages.Languages; // en-US
DateTime.Now.ToString(); // en-US
CultureInfo.CurrentCulture; // en-US
CultureInfo.CurrentUICulture; // en-US
new GeographicRegion().CodeTwoLetter; // DE, but: could be ch-DE, de-DE, xyz-DE ?!
我在 SO 上阅读了 this post,但我看不出投票最高的答案如何让我尊重用户设置的日期和时间格式(无需根据语言偏好进行疯狂猜测)。
那么,有没有一种方法可以在 Windows 商店应用程序中格式化 DateTime
实例?
您可以通过GetLocaleInfoEx Win32 API
获取正确的文化信息(用户在区域设置中设置的文化信息)
请查看 this post 了解有关此事的更多信息。
在 Windows Store 应用程序(8.1,非 UWP)中,如何获取 Windows 10 中配置的日期和时间格式?在以下示例中,安装的操作系统语言为 en-US
,时间和货币格式设置为 de-DE
.
我试过了:
new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shortdate"); // resolved language = en-US, resolved geographic region = ZZ ?!
Windows.Globalization.Language.CurrentInputMethodLanguageTag; // en-US
Windows.System.UserProfile.GlobalizationPreferences.Languages; // en-US
Windows.Globalization.ApplicationLanguages.Languages; // en-US
DateTime.Now.ToString(); // en-US
CultureInfo.CurrentCulture; // en-US
CultureInfo.CurrentUICulture; // en-US
new GeographicRegion().CodeTwoLetter; // DE, but: could be ch-DE, de-DE, xyz-DE ?!
我在 SO 上阅读了 this post,但我看不出投票最高的答案如何让我尊重用户设置的日期和时间格式(无需根据语言偏好进行疯狂猜测)。
那么,有没有一种方法可以在 Windows 商店应用程序中格式化 DateTime
实例?
您可以通过GetLocaleInfoEx Win32 API
获取正确的文化信息(用户在区域设置中设置的文化信息)请查看 this post 了解有关此事的更多信息。