【问题标题】:How to get Windows region format?如何获取 Windows 区域格式?
【发布时间】:2016-09-11 07:28:19
【问题描述】:

在 Windows 的控制面板中有一个组合框,我们可以在其中更改区域格式(controlPanel => Region => Formats (windows 10))。例如波斯语或英语

我想在我的应用程序中检索此区域设置。

我试过这样的代码:

        CultureInfo ci = CultureInfo.InstalledUICulture;
        var installed = ci.Name;

        ci = CultureInfo.CurrentUICulture;
        var currentUi = ci.Name;

        ci = CultureInfo.CurrentCulture;
        var current = ci.Name;

installedcurrentUi 始终是“en-US”,而current 是“fa-IR”

当我在控制面板中更改格式时,它们并没有改变。

【问题讨论】:

  • fa-IR 不是您所期待的吗?另外你有没有试过:start application => check culture => change region format => restart application and check again?我认为它只会在您重新启动应用程序后发生变化。
  • 我重新启动了我的应用程序,但它没有改变
  • 控制面板小程序可让您更改非当前区域的区域格式。实际上不是很有用,是吗?尽管如此,当程序更改其默认文化时,仍需要配置格式。 sn-p 中没有任何内容表明您正在这样做。

标签: c# format culture region


【解决方案1】:

我使用了这个代码。

Thread.CurrentThread.CurrentCulture.ClearCachedData();
var thread = new Thread(s => ((State)s).Result = Thread.CurrentThread.CurrentCulture);
var state = new State();
thread.Start(state);
thread.Join();
var culture = state.Result;

然后我们使用culture.Name。 在这种情况下,没有必要关闭并重新打开程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-05
    • 1970-01-01
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    相关资源
    最近更新 更多