简体   繁体   English

日期时间格式与区域性不符

[英]DateTime formatting doesn't match the culture

I have a Windows Server 2008 R2 system which is configured with the default locale settings (no overrides on the format or anything) and it's set to en-US. 我有一个Windows Server 2008 R2系统,该系统配置了默认的语言环境设置(格式上没有任何替代内容或其他内容),并将其设置为en-US。

When I interrogate the following: System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat 当我询问以下内容时: System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat

It is listing the DateSeparator as a - (dash) instead of a / (slash). 它以- (破折号)而不是/ (斜杠)列出DateSeparator。 So DateTime.Now.ToString() would look something like: 所以DateTime.Now.ToString()看起来像:

01-30-2015 . 2015年1月30日

Also, the CurrentThread.CurrentCulture.ToString() = "en-US" 另外,CurrentThread.CurrentCulture.ToString()=“ en-US”

I'm completely at a loss as to how this is even possible, but more importantly, I would like to know if .NET has some kind of a locale override which is configurable somehow? 我完全不知道该怎么办,但更重要的是,我想知道.NET是否具有某种可以以某种方式配置的语言环境覆盖?

The system Region & Language settings are normal and have not been changed. 系统的“区域和语言”设置是正常的 ,尚未更改。 Any help would be greatly appreciated, thanks. 任何帮助将不胜感激,谢谢。

Here is the code for the diagnostic information. 这是诊断信息的代码。 It's being run in asp.net on an aspx page. 它在aspx页上的asp.net中运行。

Current Date Time: <%= DateTime.Now.ToString() %>
Current Short Date: <%= DateTime.Now.ToShortDateString() %>
Current Culture: <%= System.Threading.Thread.CurrentThread.CurrentCulture.ToString() %>
Current UI Culture: <%= System.Threading.Thread.CurrentUICulture.ToString() %>

DateTimeFormatInfo invariant = CultureInfo.InvariantCulture.DateTimeForamat;
DateTimeFormatInfo uiThread = System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat;
DateTimeFormatInfo thread = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat;

Type type = System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.GetType();
foreach( var prop in type.GetProperties()) {
  <%= prop.Name %> 
  <%= prop.GetValue(invariant, null) %> <br/>
  <%= prop.GetValue(uiThread, null) %> <br/>
  <%= prop.GetValue(thread, null) %> <br/>
}

Region & Language Settings 地区和语言设置 区域和语言设置

Here is some additional information 这是一些其他信息 有关DateTimeFormat的诊断信息

Each user has different region profile. 每个用户都有不同的区域配置文件。 Your current account and application may not using same account that why you see the different value. 您当前的帐户和应用程序可能使用的帐户不同,这就是为什么您看到不同的值的原因。

Go to Region settings windows -> Administrative -> Click on Copy Settings and tick all check box (Welcome screen and system accounts + New user accounts) then click ok. 转到区域设置窗口->管理->单击复制设置,然后选中所有复选框(欢迎屏幕和系统帐户+新用户帐户),然后单击确定。 See if it fix your problem. 看看是否能解决您的问题。 If your app is Web Application you need to create another AppPool to see it affected. 如果您的应用程序是Web应用程序,则需要创建另一个AppPool才能看到它受到影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM