DateTime.DayOfWeek Property

Definition

Obtém o dia da semana representado por essa instância.Gets the day of the week represented by this instance.

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

Property Value

DayOfWeek

Uma constante enumerada que indica o dia da semana desse valor DateTime.An enumerated constant that indicates the day of the week of this DateTime value.

Examples

O exemplo a seguir demonstra a propriedade DayOfWeek e a enumeração System.DayOfWeek.The following example demonstrates the DayOfWeek property and the System.DayOfWeek enumeration.

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

Remarks

O valor das constantes na enumeração de DayOfWeek varia de DayOfWeek.Sunday para DayOfWeek.Saturday.The value of the constants in the DayOfWeek enumeration ranges from DayOfWeek.Sunday to DayOfWeek.Saturday. Se for convertido em um inteiro, seu valor vai de zero (que indica DayOfWeek.Sunday) para seis (que indica DayOfWeek.Saturday).If cast to an integer, its value ranges from zero (which indicates DayOfWeek.Sunday) to six (which indicates DayOfWeek.Saturday).

A propriedade DayOfWeek retorna uma constante enumerada; Ele não reflete as configurações regionais e de idioma do sistema.The DayOfWeek property returns an enumerated constant; it does not reflect a system's regional and language settings. Para recuperar uma cadeia de caracteres que representa um nome de dia da semana localizado para uma determinada data, chame uma das sobrecargas do método ToString que inclui um parâmetro format e passe-o ddd ou dddd cadeias de caracteres de formato personalizado.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. Para obter detalhes, consulte como: extrair o dia da semana de uma data específica.For details, see How to: Extract the Day of the Week from a Specific Date.

Applies to

See also