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) 方法。 以前的格式字符串生成缩写的工作日名称;后者生成完整的工作日名称。