我需要DateTime的帮助 我希望我的应用程序检查DateTime结束是否已启动并给我一个消息框 我怎么写呢? 代码:
private void listjob()
{
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(listjob3_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 1);
dispatcherTimer.Start();
}
private void listjob3_Tick(object sender, EventArgs e)
{
if (listbox3job())
{
DateTime? start = DateTimePicker1.Value;
DateTime? end = DateTimePicker2.Value;
DateTime now = DateTime.Now;
if (?) // here is what I want it to check if end time is started
{
Xceed.Wpf.Toolkit.MessageBox.Show("End Time started");
DispatcherTimer timer = (DispatcherTimer)sender;
timer.Stop();
timer = null;
}
}
}
答案 0 :(得分:2)
除非我非常误解你想要的东西:
if (now >= end)
或换句话说,如果当前时间大于或等于结束时间。如果您只是想知道当前时间是否超过结束时间,那么:
if (now > end)
答案 1 :(得分:0)
if(end<= now)
就是这样。如果您遇到类型问题,请使用ToShortDateString()或其他属性