C#:ShortDatePattern 给出不正确的结果

标签 c#

我的 Windows 机器有 dd-MM-yyyy 日期模式。在下面的代码中,我试图通过 C# 代码获取日期格式,但它给我的是 M/d/yyy 而不是 dd-MM-yyyy。在代码中是正确的吗?

Console.WriteLine(DateTime.Now);

  Console.WriteLine(CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern);

enter image description here

最佳答案

使用 CurrentCulture 而不是 CurrentUICulture`。

CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern

CurrentCulture 用于格式化数字和日期。
CurrentUICulture 用于本地化。

关于C#:ShortDatePattern 给出不正确的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50985561/

相关文章:

c# - 无法加载 {myassembly} 导入的过程

c# - OpenGL闪烁问题

c# - 如何忽略来自可观察序列的所有通知(错误除外)?

c# - 如何使用 Sqlite.Net 扩展过滤器

c# - 在 Web 服务中使用 Task.WhenAny()

c# - 如何使用 NServiceBus 执行集成测试?

c# - Oxyplot:蜡烛重叠每根蜡烛

c# - 如何在 Monotouch 中绑定(bind) NSObject<UIGestureRecognizerDelegate>?

c# - 是否可以在不传递容器的情况下在 CaSTLe Windsor 中使用范围限定的生活方式?

c# - 基类实现接口(interface)