如何确认当前时间在特定时间范围内? [英] How can I ckeck that the current time is within a specific time range?
本文介绍了如何确认当前时间在特定时间范围内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要比较当前时间是否在特定范围内.我尝试了以下
I need to compare that the current time is within a specific range. I've tried the following
DateTime currentTime = DateTime.Now;
int Comaprestart = DateTime.Compare(currentTime, startTime);
int CompareEnd = DateTime.Compare(currentTime,endTime);
if ((Comaprestart >= 0) && (CompareEnd <= 0))
LinkBtnQuiz.Enabled = true;
它无法正常工作.例如,我的结束时间等于"2014-06-08 13:30:00.000",当前时间等于"2014-06-08 13:12:00.000",但是我得到CompareEnd = 1,但它应该为-1当前时间早于结束时间.
It doesn't work right. for example I have the end time equal '2014-06-08 13:30:00.000' and the current time equal '2014-06-08 13:12:00.000' but I get CompareEnd=1 while it should be -1 as the current time is earlier than the end time.
关于导致错误的原因有什么想法?
Any idea of what is causing the error??
推荐答案
您可以更轻松地做到这一点:
you can do it easier:
if(currentTime >= startTime && currentTime <= endTime)
{
LinkBtnQuiz.Enabled = true;
}
这篇关于如何确认当前时间在特定时间范围内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文