改变文化不会改变日期时间格式。 [英] changing culture does not change date time Format.
本文介绍了改变文化不会改变日期时间格式。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
输入日期是2015-01-30
entered date is 2015-01-30
System.Globalization.CultureInfo en = new System.Globalization.CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentCulture = en;
DateTime dt =Convert.ToDateTime(txbuyerOrder_date.Text, en.DateTimeFormat);
dt is always {30/01/2015 12:00:00 AM}
whether culture is en-GB or en-US or anything else
推荐答案
DateTime没有 有 格式 - 它自任意时间点起存储为毫秒数,所以它只有一个数字!
只有在准备好呈现时才会获得格式ToString方法的用户bymenas,通过调用显式:
A DateTime doesn't have a format - it is stored as a number of milliseconds since an arbitrary point in time, so all it has is a number!
It only acquires a format when it is prepared for presentation to a user bymenas of the ToString method, either explicitly via a call:
string myDate = dt.ToString();
或隐含地:
Or implicitly:
Console.WriteLine(dt);
或
Or
string myDate = "The date is " + dt;
完成转换为字符串后,在执行转换的PC上生效的文化控制如何生成的字符串已格式化。
[edit]
您可以通过指定所需的确切输出格式来覆盖默认格式 - 请参阅此处: 格式化日期时间以显示 - 格式字符串说明 [ ^ ]
[/ edit]
When the conversion to a string is done, the culture in effect on the PC doing the conversion controls how the resulting string is formatted.
[edit]
You can override the default formatting by specifying the exact output format you want - see here: Formatting a DateTime for display - format string description[^]
[/edit]
这篇关于改变文化不会改变日期时间格式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文