Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: Set initial DayOfWeek as Monday not Sunday

Tags:

c#

dayofweek

Is there a way to set the first DayOfWeek as Monday = 0 not Sunday?

(int)dateList[0].DayOfWeek == 0) // 0 = Sunday
like image 589
msfanboy Avatar asked Jun 28 '10 19:06

msfanboy


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

Why is C named so?

Because a and b and c , so it's name is C. C came out of Ken Thompson's Unix project at AT&T. He originally wrote Unix in assembly language. He wrote a language in assembly called B that ran on Unix, and was a subset of an existing language called BCPL.


2 Answers

You would need to create a custom culture, and specify the initial DayOfWeek as Monday. An instance of your custom culture would need to be set to whatever context is normally used to access culture information (i.e. Thread.CurrentCulture). The following article should get you started on creating a custom culture:

How to: Create Custom Cultures

EDIT:

I just reread your question, and I noticed something. You can not change the DayOfWeek property...that is simply an enumeration value. You would need to compare the DayOfWeek to the FirstDayOfWeek property of the CultureInfo.DateTimeFormat property:

dateList[0].DayOfWeek == Thread.CurrentCulture.DateTimeFormat.FirstDayOfWeek

By default, FirstDayOfWeek is Sunday. If you created a custom culture, it could be any day of the week you so choose (i.e. Monday).

like image 153
jrista Avatar answered Oct 17 '22 23:10

jrista


DayOfWeek is an enum and so you can't change it. I have, in the past, simply adjusted the value I store to compensate and you may have to do something similar. I needed 0 = Unset.

like image 38
Nate Zaugg Avatar answered Oct 17 '22 21:10

Nate Zaugg