views:

42

answers:

2

I was suprised to see FxCop complaining that I wasn't specifying a CultureInfo in the following:

string s = day.ToString("ddd");

Surely the format string param in ToString is completely independent of CultureInfo? Is there any way which CultureInfo could affect the returned string?

EDIT: sorry, this is a total fail of a question. It's obvious that "ddd" should be dependent on culture settings. I was really thinking more of a case like DateTime.Now.ToString("dd-MM-yy"), but it looks like FxCop doesn't in fact complain in that instance.

+2  A: 

There is an article on MSDN on How to extract the Day of the Week from a Specific Date. You will find many different examples on culture on that page, including this one:

DateTime dateValue = new DateTime(2008, 6, 11);
Console.WriteLine(dateValue.ToString("ddd"));    // Displays Wed

DateTime dateValue = new DateTime(2008, 6, 11);
Console.WriteLine(dateValue.ToString("ddd", 
                  new CultureInfo("fr-FR")));    // Displays mer.
Espo
A: 
DateTime.ParseExact(day.ToString(), "ddd", DateTimeFormatInfo.InvariantInfo)

DateTimeFormatInfo.InvariantInfo gives you default culture independent DateTimeFormatInfo.

Ismail