DayOfWeek 枚举
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定一周中的某天。
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
- 继承
- 属性
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 表示日历中每周有七天的星期几。 此枚举中的常量的值从星期日到星期六不等。 如果转换为整数,则其值范围为零 (,表示星期日) 到六个 (,表示星期六) 。
如果希望具有一周日期的强类型规范,则此枚举非常有用。 例如,此枚举是属性的属性值DateTime.DayOfWeekDateTimeOffset.DayOfWeek的类型。
枚举的成员 DayOfWeek 未本地化。 若要返回星期几的本地化名称,请使用“d”或“ddd”格式字符串调用 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 |