Share via


Month 函式 (Visual Basic)

更新:2007 年 11 月

傳回介於 1 到 12 間表示年中月份的 Integer 值。

Public Function Month(ByVal DateValue As DateTime) As Integer

參數

  • DateValue
    必要項。您希望抽出月數的 Date 值。

備註

您也可以呼叫 DatePart 和指定 DateInterval.Month 的 Interval 引數,來取得年度的月數。

範例

這個範例會使用 Month 函式,從指定日期取得月份。在開發環境中會使用您程式碼中的地區設定,以簡短日期格式表示日期常值。

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

需求

命名空間 (Namespace)︰Microsoft.VisualBasic

**模組︰**DateAndTime

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

請參閱

參考

Day 函式 (Visual Basic)

Now 屬性

Weekday 函式 (Visual Basic)

Year 函式 (Visual Basic)

DatePart 函式 (Visual Basic)

System

DateTime

ArgumentException

ArgumentOutOfRangeException