Share via


DateAndTime.Year(DateTime) 方法

定義

傳回從 1 到 9999 的整數值,表示年份。

public:
 static int Year(DateTime DateValue);
public static int Year (DateTime DateValue);
static member Year : DateTime -> int
Public Function Year (DateValue As DateTime) As Integer

參數

DateValue
DateTime

必要。 您想要從中擷取年份的 Date 值。

傳回

從 1 到 9999 的整數值,表示年份。

範例

下列範例會 Year 使用 函式,從指定的日期取得年份。 在開發環境中,日期常值會使用程式代碼的地區設定,以簡短日期格式顯示。

Dim thisDate As Date
Dim thisYear As Integer
thisDate = #2/12/1969#
thisYear = Year(thisDate)
' thisYear now contains 1969.

備註

您也可以呼叫 DatePart 並指定 DateInterval.YearInterval 變數來取得年份。

適用於

另請參閱