vb.net 检查当前日期的日期和月份

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13994000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 16:31:10  来源:igfitidea点击:

Check Day & Month of Current Date

vb.netdate

提问by John White

I need to check the day and the month. I'm using Date.Now.

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

for example:

例如:

if day =9 and month=10 then do action

如果天=9 和月=10 则执行操作

How can i do that?

我怎样才能做到这一点?

回答by slolife

Use the Dayand Monthproperties of a DateTime variable:

使用DateTime 变量的DayMonth属性:

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

回答by Tim Schmelter

The Dateobject has a Dayand a Monthproperty:

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

Note that i've used Date.Todayinstead of Date.Nowsince you're interested in the date part anyway.

请注意,我使用了Date.Today而不是Date.Now因为您无论如何都对日期部分感兴趣。

回答by Jason Tyler

Date.Now.Month and Date.Now.Day. Those are properties on the Date type.

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

回答by Mark Hurd

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

回答by Peter Mankge

Date.today.day      
Date.today.month

回答by Sasiru Welgama

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