C# 使用c从系统获取当前时间格式的问题#
通过上面的代码,每当我更改系统中的日期格式时,我都可以获得当前的系统日期格式 例如:如果我更改日期格式,如yy/MM/dd。我可以得到相同的格式作为结果。但我无法获得正确的当前时间格式。即使我在我的系统中设置了日期格式,如hh:mm tt,我总是得到格式h:mm ttC# 使用c从系统获取当前时间格式的问题#,c#,C#,通过上面的代码,每当我更改系统中的日期格式时,我都可以获得当前的系统日期格式 例如:如果我更改日期格式,如yy/MM/dd。我可以得到相同的格式作为结果。但我无法获得正确的当前时间格式。即使我在我的系统中设置了日期格式,如hh:mm tt,我总是得到格式h:mm tt string dateFormate = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern; 下图显示了我可以更改系统日期和时间格式的位置 试试看 改变我们。如
string dateFormate = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
下图显示了我可以更改系统日期和时间格式的位置
试试看
改变我们。如果要使更改永久保存到正在运行的appdomain,请将System.Globalization.CultureInfo.CurrentCulture分配给en us的GetCulture
以下代码将在计算机中返回ShortDateFormat
DateTime result;
if (DateTime.TryParse("31/1/2010", System.Globalization.CultureInfo.GetCultureInfo("en-gb"),
System.Globalization.DateTimeStyles.None, out result))
MessageBox.Show(result.ToShortDateString());
else
MessageBox.Show("Not in Great Britain format");
未尝试,仅参考
参考:
参考:
使用以下链接识别区域性的LCID:
谢谢我尝试了CultureInfo中的不同文化。我得出的结论是,只有InstalledCulture才能更改操作系统设置。不过我在Windows7Pro上试过了 它与CultureInfo.InstalledCulture一起工作吗?来自MSDN 提到ShortTimePattern将为en-US文化提供h:mm tt,如截图所示
这就是为什么你会有这种行为 听起来好像你在操作系统中发现了一个缺陷。您在哪个版本的Windows上发现了此问题?.net版本与Windows是分开的。现在我使用的是Windows XP Service Pack3@STLDeveloper尽管有任何窗口/bug拖拽,但窗口中的bug通常比人类的误读/误解要少。@X.L.Ant-尽量不要把你的内裤捆在一起-我不是为了什么而拖拽。很明显,所使用的操作系统是发布的图像中的windows。
DateTime result;
if (DateTime.TryParse("31/1/2010", System.Globalization.CultureInfo.GetCultureInfo("en-gb"),
System.Globalization.DateTimeStyles.None, out result))
MessageBox.Show(result.ToShortDateString());
else
MessageBox.Show("Not in Great Britain format");
MessageBox.Show(Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern)
/*
This code produces the following output.
CULTURE PROPERTY VALUE
en-US h:mm tt
ja-JP H:mm
fr-FR HH:mm
*/