Bagikan melalui


DateTime.DayOfWeek Properti

Definisi

Mendapatkan hari dalam seminggu yang diwakili oleh instans ini.

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

Nilai Properti

Konstanta enumerasi yang menunjukkan hari dalam seminggu dari nilai ini DateTime .

Contoh

Contoh berikut menunjukkan DayOfWeek properti dan System.DayOfWeek enumerasi.

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

Keterangan

Nilai konstanta dalam DayOfWeek rentang enumerasi dari DayOfWeek.Sunday ke DayOfWeek.Saturday. Jika dilemparkan ke bilangan bulat, nilainya berkisar dari nol (yang menunjukkan DayOfWeek.Sunday) hingga enam (yang menunjukkan DayOfWeek.Saturday).

Properti DayOfWeek mengembalikan konstanta enumerasi; properti tidak mencerminkan pengaturan regional dan bahasa sistem. Untuk mengambil string yang mewakili nama hari kerja yang dilokalkan untuk tanggal tertentu, panggil salah satu kelebihan beban ToString metode yang menyertakan format parameter dan berikan string ddd format kustom atau dddd . Untuk detailnya, lihat Cara: Mengekstrak Hari Dalam Seminggu dari Tanggal Tertentu.

Berlaku untuk

Lihat juga