C# 卡控时间输入
int hour = (int.Parse(DateTime.Now.Hour.ToString())) * 60;
int minute = int.Parse(DateTime.Now.Minute.ToString());
int nowTime = hour + minute;
int hour1 = (int.Parse(txthour.Text)) * 60;
int minute1 = (int.Parse(txtmin.Text));
int oldTime = hour1 + minute1;
if ((nowTime - oldTime) > 30)
{
lblMsg.Text = "登記時間應在當前時間的前30分鐘內!" ;
lblMsg.ForeColor = System.Drawing.Color.Red;
txthour.ForeColor = System.Drawing.Color.Red;
txtmin.ForeColor = System.Drawing.Color.Red;
return;
}
else if ((nowTime - oldTime) < 0)
{
lblMsg.Text = "登記時間不應在當前時間之後!" ;
lblMsg.ForeColor = System.Drawing.Color.Red;
txthour.ForeColor = System.Drawing.Color.Red;
txtmin.ForeColor = System.Drawing.Color.Red;
return ;
}