DateTime.DayOfWeek Propriedade

Definição

Obtém o dia da semana representado por essa instância.

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

Valor da propriedade

DayOfWeek

Uma constante enumerada que indica o dia da semana desse valor DateTime.

Exemplos

O exemplo a seguir demonstra a DayOfWeek propriedade e a System.DayOfWeek enumeração .

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

Comentários

O valor das constantes nos DayOfWeek intervalos de enumeração de DayOfWeek.Sunday a DayOfWeek.Saturday . Se for cast em um inteiro, seu valor varia de zero (o que indica DayOfWeek.Sunday ) a seis (o que indica DayOfWeek.Saturday ).

A DayOfWeek propriedade retorna uma constante enumerada; ela não reflete as configurações regionais e de idioma de um sistema. 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 que inclui um parâmetro e passe-o para as cadeias de ToString format ddd caracteres de formato personalizado dddd ou . Para obter detalhes, consulte Como extrair o dia da semana de uma data específica.

Aplica-se a

Confira também