Share via


Hour 函式 (Visual Basic)

更新:2007 年 11 月

傳回介於 0 到 23 之間代表小時數的 Integer 值。

Public Function Hour(ByVal TimeValue As DateTime) As Integer

參數

  • TimeValue
    必要項。您想要抽取小時數的 Date 值。

備註

您也可以呼叫 DatePart 和指定 DateInterval.Hour 的 Interval 引數,以取得當天的時數。

範例

這個範例會使用 Hour 函式,從指定的時間取得小時。在開發環境中會根據程式碼的地區設定,以簡短時間格式表示時間常值。

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

需求

命名空間 (Namespace)︰Microsoft.VisualBasic

**模組︰**DateAndTime

組件:Visual Basic Runtime Library (在 Microsoft.VisualBasic.dll 中)

請參閱

參考

Day 函式 (Visual Basic)

Minute 函式

Now 屬性

Second 函式 (Visual Basic)

TimeOfDay 屬性

DatePart 函式 (Visual Basic)

System

DateTime

ArgumentException

ArgumentOutOfRangeException