问题描述
根据 维基百科(并在 达里奥·索莱拉的回答),他们在意大利使用冒号格式化时间:
According to Wikipedia (and confirmed in an answer by Dario Solera), in Italy they format times using colons:
在书写中使用 24 小时表示法,并以冒号作为分隔符.示例:14:05.分钟用两位数书写;小时数字可以带或不带前导零.
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.
但是,运行以下代码似乎会输出点:
However, running the following code seems to output dots:
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
等之前覆盖它?
Is this a framework bug? What's the best way to "fix" it? TimeSeparator
is settable - should we just overwrite it before assigning to Thread.CurrentThread.CurrentCulture
etc.?
推荐答案
这似乎是 .NET 3.5 的问题.在 .NET 4.0 中,您发布的代码按预期使用冒号.框架版本之间似乎有一个奇怪的突破性变化,但升级到 .NET 4 似乎可以解决问题.
This seems to be a .NET 3.5 issue. In .NET 4.0 the code you posted uses a colon as expected. Seems like a strange breaking change between the framework versions, but seems like upgrading to .NET 4 will solve the problem.
这篇关于.NET (3.5) 使用点而不是冒号来格式化时间作为 IT 文化的 TimeSeparator?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!