我正在尝试创建一个很酷的小程序,所以当它是某个特定日期时,会更改文本框或标签说出来的东西!
if (DateTime.Now.Equals(5/15/2016))
{
textBox1.Text = "Kameron it's your f***ing birthday!";
label1.Text = "It's your birthday!";
}
答案 0 :(得分:1)
您可以将其转换为DateTime
并比较Date
DateTime.Now
部分
if (DateTime.Now.Date.Equals(new DateTime(2016,5,15)))
{
textBox1.Text = "Kameron it's your f***ing birthday!";
label1.Text = "It's your birthday!";
}
或者(如@rob建议的那样)你可以使用DateTime.Today
进行比较。
if( DateTime.Today.Equals(new DateTime(2016,5,15)))
{
....
}
答案 1 :(得分:0)
试试这个
if (DateTime.Now.ToShortDateString().Equals("5/16/2016"))
{
textBox1.Text = "Kameron it's your f***ing birthday!";
label1.Text = "It's your birthday!";
}