5

我需要检查日期和月份。我正在使用Date.Now.

例如:

如果 day =9 和 month=10 然后采取行动

我怎样才能做到这一点?

4

6 回答 6

10

使用DateTime 变量的Day和属性:Month

Dim currentDate As DateTime = DateTime.Now
If currentDate.Month = 10 AndAlso currentDate.Day = 9 Then
   'Do something
End If
于 2012-12-21T16:53:13.223 回答
3

Date对象有一个Day和一个Month属性:

Dim today = Date.Today
Dim day = today.Day
Dim month = today.Month

If day = 9 AndAlso month = 10 Then
    ' do something ...
End If

请注意,我已经使用Date.Today而不是Date.Now因为您对日期部分感兴趣。

于 2012-12-21T16:52:40.640 回答
2

Date.Now.Month 和 Date.Now.Day。这些是 Date 类型的属性。

于 2012-12-21T16:51:41.083 回答
1
Dim today = Date.Now.Date
If today.Day = 9 AndAlso today.Month = 10 Then ...
于 2012-12-21T16:52:29.513 回答
0
Date.today.day      
Date.today.month
于 2016-01-27T08:58:20.107 回答
0
Dim today = Date.Today
    Dim day = today.day
    Dim month = today.Month
    Dim year = today.Year



    If day = 10 And Also month = 10 Then
        Label1.Text = today . Day
        Label2.Text = today . Month
        Label3.Text = Date . Today
        Label4.Text = Time Of Day
        Label5.Text = year
于 2018-10-10T00:14:29.243 回答