PC Review


Reply
Thread Tools Rate Thread

DateTime.DayOfWeek is not localized, why?

 
 
M
Guest
Posts: n/a
 
      8th Feb 2005
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.


 
Reply With Quote
 
 
 
 
RCS
Guest
Posts: n/a
 
      8th Feb 2005
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

"M" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
Mihai N.
Guest
Posts: n/a
 
      8th Feb 2005
> 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.

--
Mihai Nita [Microsoft MVP, Windows - SDK]
------------------------------------------
Replace _year_ with _ to get the real email
 
Reply With Quote
 
Mihai N.
Guest
Posts: n/a
 
      8th Feb 2005
"Mihai N." <(E-Mail Removed)> wrote in
news:Xns95F6E2ABB7FABMihaiN@207.46.248.16:

>> 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.
>


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

--
Mihai Nita [Microsoft MVP, Windows - SDK]
------------------------------------------
Replace _year_ with _ to get the real email
 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      8th Feb 2005
M,
In addition to the other comments.

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

http://msdn.microsoft.com/library/de...classtopic.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/de...matstrings.asp

For information on formatting in .NET in general see:
http://msdn.microsoft.com/library/de...ttingtypes.asp

Hope this helps
Jay


"M" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing DayOfWeek For A DateTime David P. Donahue Microsoft C# .NET 2 11th Jul 2006 04:11 PM
How do I convert a DateTime table column to a TimeSpan or DayOfWeek ? Harry Haller Microsoft ASP .NET 0 21st Jul 2005 12:35 PM
localized Georgian DateTime Picker COntrol? Reny J Joseph Thuthikattu Microsoft VB .NET 2 30th Jan 2005 11:49 AM
Localized datetime question Jon Microsoft VB .NET 2 21st Jan 2005 07:52 AM
DateTime.DayOfWeek localisation Gerben van Loon Microsoft C# .NET 3 13th Jan 2004 06:30 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:56 AM.