Sdílet prostřednictvím


DateTime.DayOfWeek Vlastnost

Definice

Získá den v týdnu reprezentovaný touto instancí.

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

Hodnota vlastnosti

Výčtová konstanta, která označuje den v týdnu této DateTime hodnoty.

Příklady

Následující příklad ukazuje DayOfWeek vlastnost a System.DayOfWeek výčet.

// 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.
'

Poznámky

Hodnota konstant v výčtu DayOfWeek se pohybuje od DayOfWeek.Sunday do DayOfWeek.Saturday. Při přetypování na celé číslo se jeho hodnota pohybuje od nuly (což označuje DayOfWeek.Sunday) na šest (což označuje DayOfWeek.Saturday).

Tato DayOfWeek vlastnost vrátí výčtovou konstantu; neodráží místní a jazykové nastavení systému. Chcete-li načíst řetězec představující lokalizovaný název dne v týdnu pro určité datum, zavolejte jedno z přetížení ToString metody, která obsahuje format parametr a předat jej buď ddddddd řetězce vlastního formátu. Podrobnosti najdete v tématu Postupy: Extrahování dne v týdnu z konkrétního data.

Platí pro

Viz také