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

查看:36
本文介绍了在 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天全站免登陆