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
Check Day & Month of Current Date
提问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 Day
and Month
properties of a DateTime variable:
使用DateTime 变量的Day
和Month
属性:
Dim currentDate As DateTime = DateTime.Now
If currentDate.Month = 10 AndAlso currentDate.Day = 9 Then
'Do something
End If
回答by Tim Schmelter
The Date
object has a Day
and a Month
property:
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.Today
instead of Date.Now
since 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