閱讀英文

共用方式為


DayOfWeek 列舉

定義

指定一週中的星期名稱。

C#
public enum DayOfWeek
C#
[System.Serializable]
public enum DayOfWeek
C#
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum DayOfWeek
繼承
DayOfWeek
屬性

欄位

名稱 Description
Friday 5

表示星期五。

Monday 1

表示星期一。

Saturday 6

表示星期六。

Sunday 0

表示星期天。

Thursday 4

表示星期四。

Tuesday 2

表示星期二。

Wednesday 3

表示星期三。

範例

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

C#
// 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.
*/

備註

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

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

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

適用於

產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0