Udostępnij za pośrednictwem


DayOfWeek Enumeration

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Specifies the day of the week.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<ComVisibleAttribute(True)> _
Public Enumeration DayOfWeek
[ComVisibleAttribute(true)]
public enum DayOfWeek

Members

Member name Description
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Sunday Indicates Sunday.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Monday Indicates Monday.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Tuesday Indicates Tuesday.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Wednesday Indicates Wednesday.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Thursday Indicates Thursday.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Friday Indicates Friday.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Saturday Indicates Saturday.

Remarks

The DayOfWeek enumeration represents the day of the week in calendars that have seven days per week. The value of the constants in this enumeration ranges from DayOfWeek.Sunday to DayOfWeek.Saturday. If cast to an integer, its value ranges from zero (which indicates DayOfWeek.Sunday) to six (which indicates DayOfWeek.Saturday).

This enumeration is useful when it is desirable to have a strongly typed specification of the day of the week. For example, this enumeration is the type of the property value for the DateTime.DayOfWeek property.

The members of the DayOfWeek enumeration are not localized. To return the localized name of the day of the week, call the DateTime.ToString(String) or the DateTime.ToString(String, IFormatProvider) method with either the "ddd" or "dddd" format strings. The former format string produces the abbreviated weekday name; the latter produces the full weekday name.

Examples

The following example demonstrates the DateTime.DayOfWeek property and the DayOfWeek enumeration.

' This example demonstrates the DateTime.DayOfWeek property

Class Example
   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      ' Assume the current culture is en-US.
      ' Create a DateTime for the first of May, 2003.
      Dim dt As New DateTime(2003, 5, 1)
      outputBlock.Text &= String.Format("Is Thursday the day of the week for {0:d}?: {1}", _
                         dt, dt.DayOfWeek = DayOfWeek.Thursday) & vbCrLf
      outputBlock.Text &= String.Format("The day of the week for {0:d} is {1}.", dt, dt.DayOfWeek) & vbCrLf
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'Is Thursday the day of the week for 5/1/2003?: True
'The day of the week for 5/1/2003 is Thursday.
'
// This example demonstrates the DateTime.DayOfWeek property
using System;

class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Assume the current culture is en-US.
      // Create a DateTime for the first of May, 2003.
      DateTime dt = new DateTime(2003, 5, 1);
      outputBlock.Text += String.Format("Is Thursday the day of the week for {0:d}?: {1}",
                         dt, dt.DayOfWeek == DayOfWeek.Thursday) + "\n";
      outputBlock.Text += String.Format("The day of the week for {0:d} is {1}.", dt, dt.DayOfWeek) + "\n";
   }
}
/*
This example produces the following results:

Is Thursday the day of the week for 5/1/2003?: True
The day of the week for 5/1/2003 is Thursday.
*/

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference