سؤال

I need help with DateTime.
I want my application to check if DateTime end is up and gives me a messagebox.
How do I write that?
Code:

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;
        }
    }
}
هل كانت مفيدة؟

المحلول

Unless I'm grossly misunderstanding what you want:

if (now >= end)

or in other words, if the current time is greater than or equal to the end time. If you just wanted to know if the current time is past the end time then:

if (now > end)

نصائح أخرى

if(end<= now)

It's just like that. If you have some issue with the type, use ToShortDateString() or other properties

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top