加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – .NET(3.5)使用点而不是冒号格式化时间作为IT文化的TimeSep

发布时间:2020-12-16 00:00:31 所属栏目:百科 来源:网络整理
导读:根据 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 writt
根据 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等之前覆盖它吗?

解决方法

这似乎是一个.NET 3.5问题.在.NET 4.0中,您发布的代码按预期使用冒号.看起来像框架版本之间的一个奇怪的突破性变化,但似乎升级到.NET 4将解决问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读