次の方法で共有


DateTime.DayOfWeek Property

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

Gets the day of the week represented by this instance.

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

Syntax

'Declaration
Public ReadOnly Property DayOfWeek As DayOfWeek
public DayOfWeek DayOfWeek { get; }

Property Value

Type: System.DayOfWeek
An enumerated constant that indicates the day of the week of this DateTime value.

Remarks

The value of the constants in the DayOfWeek 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).

The DayOfWeek property returns an enumerated constant; it does not reflect a system's regional and language settings. To retrieve a string representing a localized weekday name for a particular date, call one of the overloads of the ToString method that includes a format parameter and pass it either the ddd or dddd custom format strings. For details, see How to: Extract the Day of the Week from a Specific Date.

Examples

The following example demonstrates the DayOfWeek property and the System.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.