3

I was checking out the week numbering codes and I have encountered with this answer on SO. I did not get the use of CultureInfo.InvariantCulture.Calendar.GetDayOfWeek. Is there any reason for not using DayOfWeek property of DateTime as time.DayOfWeek. Am I missing something?

Related code block from the answer mentioned above:

DayOfWeek day = CultureInfo.InvariantCulture.Calendar.GetDayOfWeek(time);
Community
  • 1
  • 1
Nuri Tasdemir
  • 9,720
  • 3
  • 42
  • 67
  • IMHO Invariant culture is culture independent and time might be culture dependent. So in this code it extracts culture independent day of week from culture dependant DateTime.. – Renatas M. Jan 05 '17 at 14:46
  • Is DayOfWeek effected by culture for a given date? – Nuri Tasdemir Jan 05 '17 at 14:48
  • There is effectively no difference for the invariant culture (or indeed any other culture, as far as I can tell). So there isn't much use for this. I looked at all the implementations on ReferenceSource, and they appear to all be the same. – Matthew Watson Jan 05 '17 at 14:50
  • Well DateTime itself is not culture dependant, [it is dependant](https://msdn.microsoft.com/en-us/library/sk65c9c1(v=vs.110).aspx) on [Calendar](https://msdn.microsoft.com/en-us/library/system.globalization.calendar(v=vs.110).aspx). `ChineseLunisolarCalendar` and `GeorgianCalendar` on same date might have different day of week. – Renatas M. Jan 05 '17 at 15:01
  • It could be affect the DateTime at time you get it from input or print it as timestamp string. Say, if you input datetime by year number. You might got difference DateTime in difference machine with diffrence culture thus it could affect the day of week you expect – Thaina Yu Feb 05 '18 at 05:13

0 Answers0