DateTime.DayOfWeek Proprietà

Definizione

Ottiene il giorno della settimana rappresentato dall'istanza.

C#
public DayOfWeek DayOfWeek { get; }

Valore della proprietà

DayOfWeek

Costante enumerata che indica il giorno della settimana del valore DateTime.

Esempio

Nell'esempio seguente vengono illustrate DayOfWeek la proprietà e System.DayOfWeek l'enumerazione .

C#
// 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.
*/

Commenti

Il valore delle costanti nell'enumerazione è DayOfWeek compreso tra DayOfWeek.Sunday e DayOfWeek.Saturday . Se si esegue il cast a un numero intero, il relativo valore è compreso tra zero (che indica DayOfWeek.Sunday ) e sei (che indica DayOfWeek.Saturday ).

La proprietà restituisce una costante enumerata e non riflette le impostazioni internazionali e della lingua DayOfWeek di un sistema. Per recuperare una stringa che rappresenta un nome di giorno della settimana localizzato per una determinata data, chiamare uno degli overload del metodo che include un parametro e passarlo alle stringhe di formato personalizzate o ToString format ddd dddd . Per informazioni dettagliate, vedere Procedura: Estrarre il giorno della settimana da una data specifica.

Si applica a

Prodotto Versioni
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Vedi anche