c# - 特定于文化的 DateTime 字符串在平台之间不一致

标签 c# .net datetime cultureinfo currentculture

我有一个测试应用程序,它允许用户从 ComboBox 中选择一种文化,并在多行 TextBox 中显示特定于文化的日期。代码如下:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        comboBox1.Items.AddRange(
            CultureInfo.GetCultures(CultureTypes.SpecificCultures));
    }

    private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
    {
        CultureInfo selectedCulture = comboBox1.SelectedItem as CultureInfo;
        DateTime currentDate = DateTime.Now;

        textBox1.Text =
            "My Date : " + currentDate.ToString() + Environment.NewLine +
            "Culture Specific Date: " + currentDate.ToString(selectedCulture);
    }
}

我注意到,如果选择“ar-SA”(阿拉伯语(沙特阿拉伯)),那么当我在不同的机器上运行应用程序时,我会看到不同的结果。

在 Windows 7 机器上,文本框显示:

My Date : 4/11/2012 4:07:09 PM
Culture Specific Date: 19/05/33 04:07:09 م

在 Windows XP 机器上,文本框显示:

My Date : 4/11/2012 4:07:09 PM
Culture Specific Date: 20/05/33 04:07:09 م

如您所见,特定于文化的日期相差一天。是什么导致了这种差异?

最佳答案

怀疑这是因为 Windows XP 机器没有收到最新的 adjustments to the Umm al-Qura calendar ,而 Windows 7 系统可能会保持最新状态,但我预计这些调整不会影响当月。或者,这可能是由于:

Only recently has more information become available which now makes it possible to reconstruct the calendar adopted on the Arabian Peninsula in the recent past and to predict its future course for many years in advance.

...所以可能 Windows XP 实现已过时。

(顺便说一句,该页面同意当前是第 19 位。)

关于c# - 特定于文化的 DateTime 字符串在平台之间不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10113239/

相关文章:

PHP - 将时间加到当前时间,最佳实践

c# - jQuery 浏览器差异

c# - 为 WPF 形状启用抗锯齿

c# - 使用编辑器模板处理可空类型

C#:ToArray 性能

c# - 用于查找给定时间间隔内所有星期日和星期五的优化算法

c# - 具有大量客户端的套接字编程中的客户端到客户端通信

java - C# - 等同于 java 的 ExpectedConditions.not

c# - 如何在 PropertyGrid 中动态显示或隐藏属性?

mysql - SQL查询多个日期到一个日期