DateTime formatting does not match culture

I have a Windows Server 2008 R2 system that is configured with default locale settings (no format overrides or anything else) and it is installed in en-US.

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

It displays DateSeparator as - (dash) instead of // slash. Therefore, DateTime.Now.ToString () will look something like this:

01-30-2015.

In addition, CurrentThread.CurrentCulture.ToString () = "en-US"

I totally don’t understand how possible this is, but more importantly, I would like to know if .NET has some kind of local override that is somehow configurable?

The settings for the region and system language are normal and not changed. Any help would be greatly appreciated, thanks.

Here is the diagnostic information code. It runs in asp.net on the 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 and language settings Region and Language Settings

See below for more information. Diagnostic Information about DateTimeFormat

+5
source share
1 answer

Each user has a different area profile. Your current account and application may not use the same account, so you see a different value.

Go to the region’s settings window → Administrative → Select the “Copy options and check all” box (welcome screen and system accounts + new user accounts), then click “OK”. See if this fixes your problem. If your application is a web application, you need to create another AppPool to see its impact.

+1
source

Source: https://habr.com/ru/post/1212295/


All Articles