Is this safe, or will it only work in English-speaking countries?

72 views Asked by At

I've got this code:

Calendar cal = CultureInfo.InvariantCulture.Calendar;
String dow = cal.GetDayOfWeek(DateTime.Now).ToString();
if (dow.Equals("Monday"))

...but I wonder if it would still work in German-speaking locales ("Montag") or Spanish-speaking locales ("Lunes"). If not - if looking for "Monday" is problematic - how can I get an int that reprsents day of the week. And even in that case, is 0 always Sunday, or is it sometimes Monday (or even something else)?

1

There are 1 answers

3
Grant Winney On BEST ANSWER

It's already an enum value, so don't cast it to a string before doing the comparison:

Calendar cal = CultureInfo.InvariantCulture.Calendar;
DayOfWeek dow = cal.GetDayOfWeek(DateTime.Now);

if (dow == DayOfWeek.Monday)
{

}