我正在创建一个提醒以匹配用户输入的日期和时间。我可以使用 aTimer
和获取当前日期和时间ScriptManager
。但我不知道如何将日期和时间与用户输入进行比较,并在匹配后使下面的标签可见。有任何想法吗?
这是我的代码:
public partial class Reminder : System.Web.UI.Page
{
private void UpdateTimer()
{
LabelCurrentTime.Text = System.DateTime.Now.ToLongTimeString();
}
protected void Timer1_Tick(object sender, EventArgs e)
{
UpdateTimer();
}
protected void Button1_Click(object sender, EventArgs e)
{
string currentdate = LabelCurrentDate.Text;
string currenttime = LabelCurrentTime.Text;
string reminderdate = TextBoxReminderDate.Text;
string remindertime = TextBoxReminderTime.Text;
Timer1.Enabled = true;
LabelCurrentTime.Text = System.DateTime.Now.ToLongTimeString();
LabelCurrentDate.Text = System.DateTime.Now.Date.ToShortDateString();
if (currentdate == reminderdate)
{
if (currenttime == remindertime)
{
Label1.Visible = true;
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Timer1.Enabled = false;
}
}
这是屏幕截图: screenshot