DateAndTime.Hour(DateTime) 方法

定义

返回表示天中第几个小时的整数值,该值介于 0 和 23 之间。Returns an integer value from 0 through 23 representing the hour of the day.

public:
 static int Hour(DateTime TimeValue);
public static int Hour (DateTime TimeValue);
static member Hour : DateTime -> int
Public Function Hour (TimeValue As DateTime) As Integer

参数

TimeValue
DateTime

必需。Required. 要从中提取小时的 Date 值。A Date value from which you want to extract the hour.

返回

Int32

介于 0 和 23 之间表示一天中第几个小时的整数值。An integer value from 0 through 23 representing the hour of the day.

示例

此示例使用 Hour 函数从指定的时间获取小时。This example uses the Hour function to obtain the hour from a specified time. 在开发环境中,使用代码的区域设置以短时间格式显示时间。In the development environment, the time literal is displayed in short time format using the locale settings of your code.

Dim someTime As Date
Dim someHour As Integer
someTime = #4:35:17 PM#
someHour = Hour(someTime)
' someHour now contains 16.

注解

还可以通过调用 DatePart 并为参数指定来获取一天中的小时 DateInterval.Hour IntervalYou can also obtain the hour of the day by calling DatePart and specifying DateInterval.Hour for the Interval argument.

适用于

另请参阅