DateAndTime.Day(DateTime) 方法

定義

傳回從 1 到 31 的整數值,表示當月日期。

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

參數

DateValue
DateTime

必要。 您想要從中擷取日期的 Date 值。

傳回

從 1 到 31 的整數值,表示當月日期。

範例

下列範例會 Day 使用 函式,從指定的日期取得月份的日期。 在開發環境中,日期常值會以標準簡短格式顯示, (例如“02/12/1969”) 使用程式碼的地區設定。

Dim oldDate As Date
Dim oldDay As Integer
' Assign a date using standard short format.
oldDate = #2/12/1969#
oldDay = Microsoft.VisualBasic.DateAndTime.Day(oldDate)
' oldDay now contains 12.

Day 是限定的,可區分它與 System.Windows.Forms.Day 列舉。

備註

如果您使用 函 Day 式,您可能必須將其限定 Microsoft.VisualBasic 為 命名空間,因為 System.Windows.Forms 命名空間會 Day 定義為列舉。 下列範例示範限定如何 Day 解決此模棱兩可的情況:

Dim thisDay As Integer = Microsoft.VisualBasic.DateAndTime.Day(Now)  

您也可以呼叫 DatePartInterval 自變數並指定 DateInterval.Day ,以取得月份的日期。

適用於

另請參閱