DayOfWeek 列舉

定義

指定一週中的星期名稱。

public enum class DayOfWeek
public enum DayOfWeek
[System.Serializable]
public enum DayOfWeek
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum DayOfWeek
type DayOfWeek = 
[<System.Serializable>]
type DayOfWeek = 
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type DayOfWeek = 
Public Enum DayOfWeek
繼承
DayOfWeek
屬性

欄位

Friday 5

表示星期五。

Monday 1

表示星期一。

Saturday 6

表示星期六。

Sunday 0

表示星期天。

Thursday 4

表示星期四。

Tuesday 2

表示星期二。

Wednesday 3

表示星期三。

範例

下列範例示範 DateTime.DayOfWeek 屬性和 DayOfWeek 列舉。

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

備註

列舉 DayOfWeek 表示日曆中每週有七天的星期幾。 這個列舉中的常數值範圍從星期日到星期六。 如果轉換成整數,則其值範圍從零 (,表示星期日) 為六 (,表示星期六) 。

當想要有星期幾的強型別規格時,這個列舉就很有用。 例如,這個列舉是 和 DateTimeOffset.DayOfWeek 屬性的屬性值 DateTime.DayOfWeek 類型。

列舉的成員 DayOfWeek 不會當地語系化。 若要傳回星期一天的當地語系化名稱,請使用 「ddd」 或 「dd」 格式字串呼叫 DateTime.ToString(String)DateTime.ToString(String, IFormatProvider) 方法。 先前的格式字串會產生縮寫的工作日名稱;後者會產生完整的工作日名稱。

適用於