DateTime.DayOfWeek Właściwość

Definicja

Pobiera dzień tygodnia reprezentowany przez to wystąpienie.

public:
 property DayOfWeek DayOfWeek { DayOfWeek get(); };
public DayOfWeek DayOfWeek { get; }
member this.DayOfWeek : DayOfWeek
Public ReadOnly Property DayOfWeek As DayOfWeek

Wartość właściwości

DayOfWeek

Wyliczona stała wskazująca dzień tygodnia tej DateTime wartości.

Przykłady

W poniższym przykładzie przedstawiono DayOfWeek właściwość i wyliczenie System.DayOfWeek .

// This example demonstrates the DateTime.DayOfWeek property
using namespace System;
int main()
{
   
   // Assume the current culture is en-US.
   // Create a DateTime for the first of May, 2003.
   DateTime dt = DateTime(2003,5,1);
   Console::WriteLine(  "Is Thursday the day of the week for {0:d}?: {1}", dt, dt.DayOfWeek == DayOfWeek::Thursday );
   Console::WriteLine(  "The day of the week for {0:d} is {1}.", dt, dt.DayOfWeek );
}

/*
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
open System

// Assume the current culture is en-US.
// Create a DateTime for the first of May, 2003.
let dt = DateTime(2003, 5, 1)
printfn $"Is Thursday the day of the week for {dt:d}?: {dt.DayOfWeek = DayOfWeek.Thursday}"
printfn $"The day of the week for {dt:d} is {dt.DayOfWeek}." 

// 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 Sample
{
    public static void Main()
    {
// Assume the current culture is en-US.
// Create a DateTime for the first of May, 2003.
    DateTime dt = new DateTime(2003, 5, 1);
    Console.WriteLine("Is Thursday the day of the week for {0:d}?: {1}",
                       dt, dt.DayOfWeek == DayOfWeek.Thursday);
    Console.WriteLine("The day of the week for {0:d} is {1}.", dt, dt.DayOfWeek);
    }
}
/*
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
Class Sample
   Public Shared Sub Main()
      ' Assume the current culture is en-US.
      ' Create a DateTime for the first of May, 2003.
      Dim dt As New DateTime(2003, 5, 1)
      Console.WriteLine("Is Thursday the day of the week for {0:d}?: {1}", _
                         dt, dt.DayOfWeek = DayOfWeek.Thursday)
      Console.WriteLine("The day of the week for {0:d} is {1}.", dt, dt.DayOfWeek)
   End Sub
End Class
'
'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.
'

Uwagi

Wartość stałych w wyliczeń DayOfWeek waha się od DayOfWeek.Sunday do DayOfWeek.Saturday. Jeśli rzutowanie do liczby całkowitej, jego wartość waha się od zera (co wskazuje DayOfWeek.Sunday) na sześć (co wskazuje).DayOfWeek.Saturday

Właściwość DayOfWeek zwraca wyliczona stała; nie odzwierciedla ustawień regionalnych i językowych systemu. Aby pobrać ciąg reprezentujący zlokalizowaną nazwę dnia tygodnia dla określonej daty, wywołaj jedno z przeciążeń ToString metody zawierającej format parametr i przekaż je ciągom ddd formatu niestandardowego lub dddd . Aby uzyskać szczegółowe informacje, zobacz How to: Extract the Day of the Week from a Specific Date (Instrukcje: wyodrębnianie dnia tygodnia z określonej daty).

Dotyczy

Zobacz też