Freigeben über


DateTimeOffset.DayOfWeek Eigenschaft

Definition

Ruft den Tag der Woche ab, der durch das aktuelle DateTimeOffset-Objekt dargestellt wird.

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

Eigenschaftswert

DayOfWeek

Einer der Enumerationswerte, der den Wochentag des aktuellen DateTimeOffset-Objekts angibt.

Beispiele

Im folgenden Beispiel wird der Wochentagsname des ersten Tages jedes Monats des Jahres 2008 angezeigt.

DateTimeOffset startOfMonth = new DateTimeOffset(2008, 1, 1, 0, 0, 0,
                                         DateTimeOffset.Now.Offset);
int year = startOfMonth.Year;
do
{
   Console.WriteLine("{0:MMM d, yyyy} is a {1}.", startOfMonth, startOfMonth.DayOfWeek);
   startOfMonth = startOfMonth.AddMonths(1);
}
while (startOfMonth.Year == year);
// This example writes the following output to the console:
//    Jan 1, 2008 is a Tuesday.
//    Feb 1, 2008 is a Friday.
//    Mar 1, 2008 is a Saturday.
//    Apr 1, 2008 is a Tuesday.
//    May 1, 2008 is a Thursday.
//    Jun 1, 2008 is a Sunday.
//    Jul 1, 2008 is a Tuesday.
//    Aug 1, 2008 is a Friday.
//    Sep 1, 2008 is a Monday.
//    Oct 1, 2008 is a Wednesday.
//    Nov 1, 2008 is a Saturday.
//    Dec 1, 2008 is a Monday.
let mutable startOfMonth = DateTimeOffset(2008, 1, 1, 0, 0, 0, DateTimeOffset.Now.Offset)
let year = startOfMonth.Year

while startOfMonth.Year = year do
    printfn $"""{startOfMonth.ToString "MMM d, yyyy"} is a {startOfMonth.DayOfWeek}."""
    startOfMonth <- startOfMonth.AddMonths 1

// This example writes the following output to the console:
//    Jan 1, 2008 is a Tuesday.
//    Feb 1, 2008 is a Friday.
//    Mar 1, 2008 is a Saturday.
//    Apr 1, 2008 is a Tuesday.
//    May 1, 2008 is a Thursday.
//    Jun 1, 2008 is a Sunday.
//    Jul 1, 2008 is a Tuesday.
//    Aug 1, 2008 is a Friday.
//    Sep 1, 2008 is a Monday.
//    Oct 1, 2008 is a Wednesday.
//    Nov 1, 2008 is a Saturday.
//    Dec 1, 2008 is a Monday.
Dim startOfMonth As New DateTimeOffset(#1/1/2008#, _
                                      DateTimeOffset.Now.Offset)
Dim year As Integer = startOfMonth.Year
Do While startOfMonth.Year = year
   Console.WriteLine("{0:MMM d, yyyy} is a {1}.", _
                     startOfMonth, startOfMonth.DayOfWeek)
   startOfMonth = startOfMonth.AddMonths(1)                   
Loop      
' This example writes the following output to the console:
'    Jan 1, 2008 is a Tuesday.
'    Feb 1, 2008 is a Friday.
'    Mar 1, 2008 is a Saturday.
'    Apr 1, 2008 is a Tuesday.
'    May 1, 2008 is a Thursday.
'    Jun 1, 2008 is a Sunday.
'    Jul 1, 2008 is a Tuesday.
'    Aug 1, 2008 is a Friday.
'    Sep 1, 2008 is a Monday.
'    Oct 1, 2008 is a Wednesday.
'    Nov 1, 2008 is a Saturday.
'    Dec 1, 2008 is a Monday.

Hinweise

Der Wert der Konstanten in der DayOfWeek Enumeration reicht von DayOfWeek.Sunday zu DayOfWeek.Saturday. Wenn sie in eine ganze Zahl umgewandelt wird, liegt der Wert zwischen Null (was angibt DayOfWeek.Sunday) auf sechs (was angibt DayOfWeek.Saturday).

Sie können auch den Wochentagsnamen eines bestimmten Datums anzeigen, indem Sie den "D"-Formatbezeichner oder den benutzerdefinierten Formatbezeichner "dddd" verwenden. Beispiel:

DateTimeOffset displayDate = new DateTimeOffset(2008, 1, 1, 13, 18, 00,
                                                DateTimeOffset.Now.Offset);
Console.WriteLine("{0:D}", displayDate);  // Output: Tuesday, January 01, 2008
Console.WriteLine("{0:d} is a {0:dddd}.",
                  displayDate);           // Output: 1/1/2008 is a Tuesday.
let displayDate = DateTimeOffset(2008, 1, 1, 13, 18, 00, DateTimeOffset.Now.Offset)
printfn $"{displayDate:D}"                          // Output: Tuesday, January 01, 2008
printfn $"{displayDate:d} is a {displayDate:dddd}." // Output: 1/1/2008 is a Tuesday.
Dim displayDate As New DateTimeOffset(#1/1/2008 1:18PM#, _
                                      DateTimeOffset.Now.Offset)
Console.WriteLine("{0:D}", displayDate)    ' Output: Tuesday, January 01, 2008                     
Console.WriteLine("{0:d} is a {0:dddd}.", _
                  displayDate)             ' Output: 1/1/2008 is a Tuesday.

Beachten Sie, dass die zurückgegebene Zeichenfolge durch Aufrufen der ToString Methode des Enumerationselements DayOfWeek , das von dieser Eigenschaft zurückgegeben wird, nicht lokalisiert ist. Um eine Zeichenfolge zu extrahieren, die den Wochentagsnamen der aktuellen Kultur oder einer bestimmten Kultur enthält, rufen Sie die ToString Methode mit dem benutzerdefinierten Formatbezeichner "dddd" auf. Der folgende Code zeigt z. B. den Wochentagsnamen für ein Datum mit der fr-fr Kultur an.

DateTimeOffset thisDate = new DateTimeOffset(2007, 6, 1, 6, 15, 0,
                                             DateTimeOffset.Now.Offset);
string weekdayName = thisDate.ToString("dddd",
                                       new CultureInfo("fr-fr"));
Console.WriteLine(weekdayName);                  // Displays vendredi
let thisDate = DateTimeOffset(2007, 6, 1, 6, 15, 0, DateTimeOffset.Now.Offset)
let weekdayName = thisDate.ToString("dddd", CultureInfo "fr-fr")
printfn $"{weekdayName}"                  // Displays vendredi
Dim thisDate As New DateTimeOffset(#6/1/2007 6:15AM#, _
                                      DateTimeOffset.Now.Offset)
Dim weekdayName As String = thisDate.ToString("dddd", _
                            New CultureInfo("fr-fr")) 
Console.WriteLine(weekdayName)                        ' Displays vendredi

Gilt für