C#DateTime转换不同机器上的相同区域性 [英] C# DateTime conversion same culture on different machines

查看:185
本文介绍了C#DateTime转换不同机器上的相同区域性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我从测试的意大利机器上运行此控制台应用程序:

If i run this console app from my test italian machine:

static void Main(string[] args)
    {
        String date = DateTime.Now.ToString("yyyy-MM-dd HH:mm", new CultureInfo("it-IT"));
        Console.WriteLine(date);
        Console.ReadKey();
        CultureInfo ci = new CultureInfo("it-IT");
                Console.WriteLine("Time: " + ci.Name + " " + ci.DateTimeFormat.TimeSeparator);
                Console.WriteLine("Date: " + ci.Name + " " + ci.DateTimeFormat.DateSeparator);
        Console.ReadKey();
    }

显示:


2013-07-25 15:40时间:it-IT:日期:it-It /

2013-07-25 15:40 Time: it-IT : Date: it-It /

但如果我从美国服务器运行此代码:

but if I run this code from my usa server:


2013-07-25 15.40时间:it-IT。日期:it-It /

2013-07-25 15.40 Time: it-IT . Date: it-It /

为什么时间部分使用不同的格式分隔符?意大利语的正确答案必须是

Why different format separator for the time part? The correct one for italian must be :

推荐答案

您发现自己Windows版本之间,意大利语时间分隔符的数据已更改(冒号是最新版本)。可以预期,因为我们正在改善数据。如果是由于在计算机之间传输数据而发现此问题,则应使用标准不变格式(例如ISO 8601),该格式不受数据更改的影响。

You found out yourself that the data for the time separator for Italian changed between versions of Windows (colon is the more up-to-date version). This is expected as we are improving our data. If you found this because of transferring data between machines, you should be using standard invariant formats (like ISO 8601) that will be immune to data changes.

这篇关于C#DateTime转换不同机器上的相同区域性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆