共用方式為


DateAndTime.Hour 方法

傳回 0 到 23 的 Integer 值,表示一天中的小時。

命名空間: Microsoft.VisualBasic
組件: Microsoft.VisualBasic (在 microsoft.visualbasic.dll 中)

語法

'宣告
Public Shared Function Hour ( _
    TimeValue As DateTime _
) As Integer
'用途
Dim TimeValue As DateTime
Dim returnValue As Integer

returnValue = DateAndTime.Hour(TimeValue)
public static int Hour (
    DateTime TimeValue
)
public:
static int Hour (
    DateTime TimeValue
)
public static int Hour (
    DateTime TimeValue
)
public static function Hour (
    TimeValue : DateTime
) : int

參數

  • TimeValue
    必要項。您想從中取出小時的 Date 值。

傳回值

傳回 0 到 23 的 Integer 值,表示一天中的小時。

備註

如需詳細資訊,請參閱 Visual Basic 的主題 Hour 函式 (Visual Basic)

您也可以藉由呼叫 DatePart 以及為 Interval 引數指定 DateInterval.Hour,取得一天中的小時。

範例

此範例使用 Hour 函式,從指定之時間取得小時。在開發環境中會使用您程式碼中的地區設定,以標準簡短格式表示日期常值。

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

平台

Windows 98、 Windows 2000 SP4、 Windows CE、 Windows Millennium Edition、 Windows Mobile for Pocket PC、 Windows Mobile for Smartphone、 Windows Server 2003、 Windows XP Media Center Edition、 Windows XP Professional x64 Edition、 Windows XP SP2、 Windows XP Starter Edition

.NET Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱系統需求一節的內容。

版本資訊

.NET Framework

支援版本:2.0、1.1、1.0

.NET Compact Framework

支援版本:2.0、1.0

請參閱

參考

DateAndTime 類別
DateAndTime 成員
Microsoft.VisualBasic 命名空間
System
DateTime
ArgumentException
ArgumentOutOfRangeException

其他資源

Hour 函式 (Visual Basic)
Day 函式 (Visual Basic)
Minute 函式
Now 屬性
Second 函式 (Visual Basic)
TimeOfDay 屬性
DatePart 函式 (Visual Basic)