我使用DateTime.UtcNow.ToLongTimeString()
来获取当前时间字符串。DateTime.ToLongTimeString()生成不同的字符串
但它表现奇怪,有时它返回时间如3:10:00
有时像03:10:00
(前导零)。为什么会发生?
我设置应用程序启动
Thread.CurrentThread.CurrentCulture = new CultureInfo(...);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(...);
文化,并为时间字符串不同的结果来自于一个任务(从我现在看到)。所以我创建了一个任务,并且为它完成了.Wait()
。在任务内部,时间被转换为不同的字符串。
UPDATE
对于那些谁有兴趣,这里是一些有用的阅读中,我发现:
Is there a way of setting culture for a whole application? All current threads and new threads?
http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.defaultthreadcurrentculture.aspx
那么你是否随时随地更改“文化”? – V4Vendetta
这是改变UI线程文化的危险。工作者线程毁了你的一天。是的,.NET 4.5有一个修复它。 –