根据 Wikipedia (并在 an answer by Dario Solera 中确认),在意大利,他们使用冒号格式化时间:
The 24-hour notation is used in writing with a colon as a separator. Example: 14:05. The minutes are written with two digits; the hour numbers can be written with or without leading zero.
但是,运行下面的代码似乎会输出点:
using System.Globalization;
Thread.CurrentThread.CurrentCulture = new CultureInfo("it-IT");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("it-IT");
// Outputs "11.08"
Console.WriteLine(DateTime.Now.ToShortTimeString());
// Outputs "."
Console.WriteLine(new CultureInfo("it-IT").DateTimeFormat.TimeSeparator);
这是一个框架错误吗? “修复”它的最佳方法是什么? TimeSeparator
是可设置的 - 我们是否应该在分配给 Thread.CurrentThread.CurrentCulture
等之前覆盖它?
最佳答案
我可以保证在意大利我们使用冒号分隔小时和分钟数字,并且我们使用 24 小时格式。维基百科是正确的(至少这次是这样)。
您的问题可能是您没有设置 Thread 的 UI 文化。这样的事情应该有效:
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("it-IT");
关于c# - .NET (3.5) 使用点而不是冒号作为 IT 文化的 TimeSeparator 来格式化时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37440946/