检查日&当前日期的月份

时间:2012-12-21 16:46:26

标签: vb.net date

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

例如:

如果day = 9且month = 10则 做行动

我该怎么做?

6 个答案:

答案 0 :(得分:9)

使用DateTime变量的DayMonth属性:

Dim currentDate As DateTime = DateTime.Now
If currentDate.Month = 10 AndAlso currentDate.Day = 9 Then
   'Do something
End If

答案 1 :(得分:3)

Date对象有DayMonth属性:

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,因为您对日期部分感兴趣。

答案 2 :(得分:2)

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

答案 3 :(得分:1)

Dim today = Date.Now.Date
If today.Day = 9 AndAlso today.Month = 10 Then ...

答案 4 :(得分:0)

Date.today.day      
Date.today.month

答案 5 :(得分: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