Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

When I interrogate the following: System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat

It is listing the DateSeparator as a - (dash) instead of a / (slash). So DateTime.Now.ToString() would look something like:

01-30-2015.

Also, the 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?

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.

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 Region and Language Settings

Here is some additional information Diagnostic Information about DateTimeFormat

like image 346
inventor_josh Avatar asked Jan 30 '15 18:01

inventor_josh


1 Answers

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.

like image 108
Khoa Le Avatar answered Sep 19 '22 15:09

Khoa Le