在UWP中获取用户指定的长日期格式 [英] Get user specified long date format in UWP

查看:92
本文介绍了在UWP中获取用户指定的长日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将日期转换为用户设置的长日期格式。当前区域性是美国,但是用户可以在控制面板->区域->长日期中设置自己选择的长日期格式。

I want to convert a date to the user set long date format. The Current Culture is en-US, but the user is able to set a long date format of his/her choice in Control panel -> Region -> Long Date.

在这种情况下,在这里我将格式设置为匈牙利语,然后选择yyyy。 MMMM d。格式(将当前文化保留在美国)。

In this case, here I set the Format to Hungarian, and selected the yyyy. MMMM d. format (keeping the Current Culture in en-US).

System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FullDateTimePattern返回错误的模式。

System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FullDateTimePattern returns an incorrect pattern.

Windows.Globalization API也是如此。

So does the Windows.​Globalization API.

在我的Package.appxmanifest中:

In my Package.appxmanifest:

  <Resources>
    <Resource Language="x-generate" />
  </Resources>

有人知道如何从控制面板->区域->长日期中获取日期格式吗?

Anyone knows how to get the date format from control panel -> region -> long date?

推荐答案

不幸的是,UWP API并未公开区域设置。话虽如此,我确实找到了工作解决方案一段时间以前,尽管我尚未使用Creators Update对其进行测试,所以无法确认它是否仍然有效!

Unfortunately, the UWP API's don't expose the Regional Settings; having said that I did find a working solution a while back, though I haven't tested it with Creators Update so can't confirm if it still works!

更新:找到一种非黑客方式使用 GetLocaleInfoEx Win32 API。

Update: I've found a non-hacky way of doing this, using the GetLocaleInfoEx Win32 API.

这篇关于在UWP中获取用户指定的长日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆