Title: Get the name of the first day of the week in C#
Different cultures start the week with a different first day of the week. For example, some cultures start the week with Monday and others start it with Sunday. Usually it doesn't matter which day is the first day of the week, but if a program is drawing a calendar it will look more natural to the user if weeks start with the correct day.
The System.Globalization namespace's CultureInfo.CurrentCulture.DateTimeFormat.DayNames value is an array holding the names of the days of the week for the computer's locale. The first entry gives the name of the first day of the week.
This example uses the following code to display the name of the first day of the week.
lblResult.Text = "The first day of the week is " +
CultureInfo.CurrentCulture.DateTimeFormat.DayNames[0];
That's all there is to it. Of course if you are drawing a calendar, you'll have more work to do.
Download the example to experiment with it and to see additional details.
|