Year 函式 (Visual Basic)
更新:2007 年 11 月
傳回介於 1 到 9999 間代表年份的 Integer 值。
Public Function Year(ByVal DateValue As DateTime) As Integer
參數
- DateValue
必要項。您希望擷取年份的 Date 值。
備註
您也可以呼叫 DatePart 和指定 Interval 引數的 DateInterval.Year 來取得年份。
範例
下列範例使用 Year 函式來從指定日期取得年份。在開發環境中會使用您程式碼中的地區設定,以簡短日期格式表示日期常值。
Dim thisDate As Date
Dim thisYear As Integer
thisDate = #2/12/1969#
thisYear = Year(thisDate)
' thisYear now contains 1969.
需求
**模組:**DateAndTime
**組件 (Assembly):**Visual Basic Runtime Library (在 Microsoft.VisualBasic.dll 中)