DayOfWeek DayOfWeek DayOfWeek DayOfWeek Enum

定义

指定一周的某天。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
继承
属性

字段

Friday Friday Friday Friday 5

表示星期五。Indicates Friday.

Monday Monday Monday Monday 1

表示星期一。Indicates Monday.

Saturday Saturday Saturday Saturday 6

表示星期六。Indicates Saturday.

Sunday Sunday Sunday Sunday 0

表示星期日。Indicates Sunday.

Thursday Thursday Thursday Thursday 4

表示星期四。Indicates Thursday.

Tuesday Tuesday Tuesday Tuesday 2

表示星期二。Indicates Tuesday.

Wednesday Wednesday Wednesday 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
Imports System

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 'Main
End Class 'Sample
'
'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.DayOfWeek属性。For example, this enumeration is the type of the property value for the DateTime.DayOfWeek property.

成员DayOfWeek枚举未进行本地化。The members of the DayOfWeek enumeration are not localized. 若要返回的日期是星期几的本地化的名称,请调用DateTime.ToString(String)DateTime.ToString(String, IFormatProvider)方法使用的"ddd"或"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.

适用于