文化特定的DateTime字符串在平台之间是不一致的 [英] Culture specific DateTime string is inconsistent between platforms
问题描述
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 =
我的日期:+ currentDate.ToString()+ Environment.NewLine +
文化特定日期:+ currentDate.ToString(selectedCulture);
}
}
我注意到,如果ar-SA,阿拉伯语(沙特阿拉伯)被选中,那么当我在不同的机器上运行应用程序时,我看到不同的结果。
在Windows 7机器上,文本框显示:
我的日期:4/11/2012 4:07:09 PM
文化特定日期:19/05/33 04:07:09م
在Windows XP机器上,文本框显示:
我的日期:4/11/2012 4:07:09 PM
文化特定日期:20/05/33 04:07:09م
如您所见,文化具体日期一天下来可能导致这种差异?
我怀疑这是因为Windows XP机器不接收最新的对Umm al-Qura日历的调整,而可能Windows 7框保持最新,虽然我不希望这些调整影响当月。或者,可能是由于这个原因:
只有最近才有更多的信息可用,现在可以重建在阿拉伯半岛在最近过去,并提前预测其未来的路线。
...所以也许Windows XP实现已经过时了。
(该页面同意,目前是第19名,顺便说一句。)
I have a test application that allows the user to select a culture from a ComboBox and displays the culture specific date in a multiline TextBox. The code is below:
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);
}
}
I notice that if "ar-SA", Arabic (Saudi Arabia), is selected, then I see different results when I run the application on different machines.
On a Windows 7 machine, the text box displays:
My Date : 4/11/2012 4:07:09 PM Culture Specific Date: 19/05/33 04:07:09 م
On a Windows XP machine, the text box displays:
My Date : 4/11/2012 4:07:09 PM Culture Specific Date: 20/05/33 04:07:09 م
As you can see, the culture specific date is off by a day. What could be causing this discrepancy?
I suspect this is due to the Windows XP machine not receiving up-to-date adjustments to the Umm al-Qura calendar, whereas presumably the Windows 7 box is kept up to date, although I wouldn't expect those adjustments to affect the current month. Alternatively, it could be due to this:
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.
... so maybe the Windows XP implementation is out of date.
(That page agrees that it's currently the 19th, by the way.)
这篇关于文化特定的DateTime字符串在平台之间是不一致的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!