Urma
Urma

Reputation: 320

C# Changing CurrentCulture DateTimeFormat not working

I try to add to my ASP.NET Website new language support (English).

But all my dateTime format changed from

enter image description here

to

enter image description here

when I change language to "en-EN".

To solve it I write following code:

CultureInfo cultureInfo = new CultureInfo("en-EN");
cultureInfo.DateTimeFormat.FullDateTimePattern = "dddd, d MMMM yyyy 'y.'";
cultureInfo.DateTimeFormat.FullDateTimePattern = "dd MMMM yyyy  'y.'";
cultureInfo.DateTimeFormat.FullDateTimePattern = "d MMMM yyyy 'y.'";
cultureInfo.DateTimeFormat.DateSeparator = ".";
cultureInfo.DateTimeFormat.ShortDatePattern = "d.M.yy";
cultureInfo.DateTimeFormat.ShortDatePattern = "d.MM.yy";
cultureInfo.DateTimeFormat.ShortDatePattern = "dd.MM.yyyy";

System.Threading.Thread.CurrentThread.CurrentCulture = cultureInfo;
System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo;

But my dateTime format still like d\M\yyyy.

What is wrong? Please help!

Upvotes: 0

Views: 4507

Answers (3)

user3113070
user3113070

Reputation: 13

you need to change server or local computer date settings For example: Settings--> Time & Language --> Region --> Format:( Here you need to change country) --> Additional Settings --> Date You can change date format

Good Luck :)

Upvotes: 1

Guy Park
Guy Park

Reputation: 1037

You might be experiencing that en-EN is the Original English (as in English English and not American English), which represent date values with forward/back-slashes, while American notation of dates usually use dashes (-). If you use Excel, try typing in a date with dashes and forward slashes for the 2nd of January, and you should see it the different notations flip the the numbers around.

What you're experiencing is probably .NET enforcing the correct Cultural Notation, but you should still be able to format the date like @Md._Abdul_Alim mentioned using the .toString(format).

https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

Upvotes: 0

Ankur Tripathi
Ankur Tripathi

Reputation: 472

Check this complete understanding of time formatting:- https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

Examples:-

DateTime.Now.ToString("MM/dd/yyyy") 05/29/2015
DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015
DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 05:50
DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 05:50 AM
DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 5:50
DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 5:50 AM
DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss")    Friday, 29 May 2015 05:50:06
DateTime.Now.ToString("MM/dd/yyyy HH:mm")   05/29/2015 05:50
DateTime.Now.ToString("MM/dd/yyyy hh:mm tt")    05/29/2015 05:50 AM
DateTime.Now.ToString("MM/dd/yyyy H:mm")    05/29/2015 5:50
DateTime.Now.ToString("MM/dd/yyyy h:mm tt") 05/29/2015 5:50 AM
DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")    05/29/2015 05:50:06
DateTime.Now.ToString("MMMM dd")    May 29
DateTime.Now.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss.fffffffK") 2015-05-16T05:50:06.7199222-04:00
DateTime.Now.ToString("ddd, dd MMM yyy HH’:’mm’:’ss ‘GMT’") Fri, 16 May 2015 05:50:06 GMT
DateTime.Now.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss")  2015-05-16T05:50:06
DateTime.Now.ToString("HH:mm")  05:50
DateTime.Now.ToString("hh:mm tt")   05:50 AM
DateTime.Now.ToString("H:mm")   5:50
DateTime.Now.ToString("h:mm tt")    5:50 AM
DateTime.Now.ToString("HH:mm:ss")   05:50:06
DateTime.Now.ToString("yyyy MMMM")  2015 May

Upvotes: 1

Related Questions