DateAndTime.Weekday(DateTime, FirstDayOfWeek) 方法

定义

返回包含表示星期几的数字的整数值。Returns an integer value containing a number representing the day of the week.

public static int Weekday (DateTime DateValue, Microsoft.VisualBasic.FirstDayOfWeek DayOfWeek = Microsoft.VisualBasic.FirstDayOfWeek.Sunday);
static member Weekday : DateTime * Microsoft.VisualBasic.FirstDayOfWeek -> int
Public Function Weekday (DateValue As DateTime, Optional DayOfWeek As FirstDayOfWeek = Microsoft.VisualBasic.FirstDayOfWeek.Sunday) As Integer

参数

DateValue
DateTime

必需。Required. 要确定属于一周中的哪一天的 Date 值。A Date value for which you want to determine the day of the week.

DayOfWeek
FirstDayOfWeek

可选。Optional. FirstDayOfWeek 枚举中选择的值,用于指定一周的第一天。A value chosen from the FirstDayOfWeek enumeration that specifies the first day of the week. 如果未指定,则使用 SundayIf not specified, Sunday is used.

返回

包含表示星期几的数字的整数值。An integer value containing a number representing the day of the week.

异常

DayOfWeek 小于 0 或大于 7。DayOfWeek is less than 0 or more than 7.

示例

下面的示例使用Weekday函数从指定的日期获取一周中的某一天。The following example uses the Weekday function to obtain the day of the week from a specified date.

Dim oldDate As Date
Dim oldWeekDay As Integer
oldDate = #2/12/1969#
oldWeekDay = Weekday(oldDate)
' oldWeekDay now contains 4 because thisDate represents a Wednesday.

注解

Weekday函数返回的值对应于FirstDayOfWeek枚举的值; 也就是说,1表示星期日,7表示星期六。The value returned by the Weekday function corresponds to the values of the FirstDayOfWeek enumeration; that is, 1 indicates Sunday and 7 indicates Saturday.

备注

Weekday使用CurrentCulture 命名System.Globalization空间中CultureInfo类的属性的当前日历设置。Weekday uses the current calendar setting from the CurrentCulture property of the CultureInfo class in the System.Globalization namespace. 默认CurrentCulture值由 "控制面板" 设置确定。The default CurrentCulture values are determined by Control Panel settings.

DayOfWeek参数可以具有下列设置之一。The DayOfWeek argument can have one of the following settings.

枚举值Enumeration value Value 说明Description
FirstDayOfWeek.System 00 系统设置中指定的周的第一天First day of week specified in system settings
FirstDayOfWeek.Sunday 11 星期日(默认值)Sunday (default)
FirstDayOfWeek.Monday 22 星期一(符合 ISO 标准8601,第3.17 节)Monday (complies with ISO standard 8601, section 3.17)
FirstDayOfWeek.Tuesday 33 星期二Tuesday
FirstDayOfWeek.Wednesday 44 星期三Wednesday
FirstDayOfWeek.Thursday 55 星期四Thursday
FirstDayOfWeek.Friday 66 星期五Friday
FirstDayOfWeek.Saturday 77 星期六Saturday

适用于

另请参阅