DayOfWeek 枚举

定义

指定一周的某天。Specifies the day of the week.

public enum class DayOfWeek
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum DayOfWeek
type DayOfWeek = 
Public Enum DayOfWeek
继承
DayOfWeek
属性

字段

Friday 5

表示星期五。Indicates Friday.

Monday 1

表示星期一。Indicates Monday.

Saturday 6

表示星期六。Indicates Saturday.

Sunday 0

表示星期日。Indicates Sunday.

Thursday 4

表示星期四。Indicates Thursday.

Tuesday 2

表示星期二。Indicates Tuesday.

Wednesday 3

表示星期三。Indicates Wednesday.

示例

下面的示例演示DateTime.DayOfWeek了属性DayOfWeek和枚举。The following example demonstrates the DateTime.DayOfWeek property and the DayOfWeek enumeration.

// 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
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枚举表示每周七天的日历中的第几天。The DayOfWeek enumeration represents the day of the week in calendars that have seven days per week. 此枚举中的常量值介于星期日和星期六之间。The value of the constants in this enumeration ranges from Sunday to Saturday. 如果强制转换为整数, 则其值范围为 0 (表示星期日) 到 6 (表示星期六)。If cast to an integer, its value ranges from zero (which indicates Sunday) to six (which indicates Saturday).

如果希望具有一周中某天的强类型规范, 此枚举非常有用。This enumeration is useful when it is desirable to have a strongly typed specification of the day of the week. 例如, 此枚举是DateTime.DayOfWeekDateTimeOffset.DayOfWeek属性的属性值的类型。For example, this enumeration is the type of the property value for the DateTime.DayOfWeek and DateTimeOffset.DayOfWeek properties.

未本地化DayOfWeek枚举的成员。The members of the DayOfWeek enumeration are not localized. 若要返回一周中某天的本地化名称, 请通过DateTime.ToString(String) "ddd DateTime.ToString(String, IFormatProvider) " 或 "dddd" 格式字符串调用或方法。To return the localized name of the day of the week, call the DateTime.ToString(String) or the DateTime.ToString(String, IFormatProvider) method with either the "ddd" or "dddd" format strings. 以前的格式字符串生成缩写的星期几名称;后者产生完整的星期几名称。The former format string produces the abbreviated weekday name; the latter produces the full weekday name.

适用于