简体   繁体   中英

c# date formatting issue with Culture info

I try to format a local date into a string, but based on the local format. By example, for the 5 May 2020, if I use French, I expected "5 Mai, 2020", but I got "5 May, 2020"...

The month name is still in English !

Here is my code to test this:

https://dotnetfiddle.net/saZJ0S

Do you have any idea?

Thx

You need to use the DateTime.ToString overload that gets CultureInfo parameter as a second argument.

https://docs.microsoft.com/en-us/dotnet/api/system.datetime.tostring?view=netcore-3.1

So your code would look like (copying from the image you attached):

string FormattedPostDate = localDate.ToString(CultureInfo.GetCultureInfo("fr-FR").DateTimeFormat.MonthDayPattern, new System.Globalization.CultureInfo("fr-FR")) + ", " + localDate.Year;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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