代码:
private void button1_Click(object sender, EventArgs e)
{
// string date = textBox1.Text + "-" + textBox2.Text + "-" + textBox3.Text;
string input_date = dateTimePicker1.Text;
// Console.WriteLine(input_date);
DateTime dt = Convert.ToDateTime(input_date);
int y = dt.Year;
int m = dt.Month; // 获取月
int d = dt.Day; // 获取日
string date = m.ToString() + "-" + d.ToString();
DateTime birth = Convert.ToDateTime(date);
DateTime today = DateTime.Today.Date;
string week = dt.DayOfWeek.ToString();
if (DateTime.Compare(birth, today) > 0)
{
label5.Text = "您的"+(today.Year-y)+"岁生日还有" + (birth - today).Days + "天,那天是" + week;
}
if (DateTime.Compare(birth, today) == 0)
{
label5.Text = "祝你"+(today.Year-y)+"生日快乐!";
}
if (DateTime.Compare(birth, today) < 0)
{
label5.Text = "您的" + (today.Year - y) + "生日已过" + (today - birth).Days + "天,那天是" + week;
}
}
截图: