DateTime.DayOfWeek is not localized, why?

  • Thread starter Thread starter M
  • Start date Start date
M

M

Hello,

I have code like
dt.DayOfWeek.ToString(CultureInfo.CurrentCulture)
where dt is a DateTime object.

I get something like "Sunday", "Monday", etc... while I'm expecting it to be
in French. I have a bilingual app in English and French. I don't have any
problem elsewhere, like when outputting the month for example, but DayOfWeek
is not working as I expected.

Any help is appreciated.

Thanks.
 
CultureInfo.CurrentUICulture gets it runtime versus compile time. Are you
compiling on an english machine and running it on a french machine??

Also, I'd try dumping out the cultures (.GetCultures()) to make sure .NET
recognizes what you think it does..

HTH
 
CultureInfo.CurrentUICulture gets it runtime versus compile time. Are you
compiling on an english machine and running it on a french machine??

Also, I'd try dumping out the cultures (.GetCultures()) to make sure .NET
recognizes what you think it does..
CurrentCulture and CurrentUICulture depend only on the system running the
application, not on the system you compiling it.
Otherwise good advices.
 
CurrentCulture and CurrentUICulture depend only on the system running the
application, not on the system you compiling it.
Otherwise good advices.

Oups! I was not carefull enough!
dt.ToString("dddd", CultureInfo.CurrentCulture.DateTimeFormat);
should do.

CurrentCulture matches the user locale and the CurrentUICulture matches
the OS/MUI language.

This is unless you manualy change
System.Threading.Thread.CurrentThread.CurrentCulture or
System.Threading.Thread.CurrentThread.CurrentUICulture
 
M,
In addition to the other comments.

DateTime.DayOfWeek returns an enum, enums unfortunately are not localized.

http://msdn.microsoft.com/library/d...cpref/html/frlrfsystemdayofweekclasstopic.asp

Fortunately! You should be able to use a custom date format of either "ddd"
(abbreviated) or "dddd" (full) to get localized day names:

dt.ToString("dddd")

For details on custom datetime formats see:

http://msdn.microsoft.com/library/d...s/cpguide/html/cpcondatetimeformatstrings.asp

For information on formatting in .NET in general see:
http://msdn.microsoft.com/library/d...y/en-us/cpguide/html/cpconformattingtypes.asp

Hope this helps
Jay
 
Back
Top