سؤال

I can't figure out how to properly localize DateTime.DayOfWeek in .NET 2.0.

Example:

DateTime date = DateTime.Now;

// Works fine
string localizedDate = date.ToString("D", new CultureInfo("fr-FR"));

// Nope...
string localizedDay = date.DayOfWeek.ToString("D", new CultureInfo("fr-FR")); 

I'm restricted to .NET 2.0, is that the problem?

هل كانت مفيدة؟

المحلول

DateTimeFormatInfo is supported since .NET 2.0, so this is not the case.

Try this instead:

DateTime.Now.ToString("dddd", new System.Globalization.CultureInfo("fr-FR"));

نصائح أخرى

Your second example:

string localizedDay = date.DayOfWeek.ToString("D", new CultureInfo("fr-FR"));

is using an Enumeration Format String, in which the "D" format specifier means "return the shortest representation possible".

You could try:

string localizedDay = new CultureInfo("fr-FR").DateTimeFormat.DayNames[(int)date.DayOfWeek];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top