C#日期和时间功能

时间:2012-03-22 10:24:19

标签: c#

我希望我的程序检查当前系统时间并使用它来显示当时的时间是非峰值还是峰值。请帮忙。感谢

2 个答案:

答案 0 :(得分:3)

试试这个:

        if (
                DateTime.Now.DayOfWeek != DayOfWeek.Saturday &&  // it's not saturday
                DateTime.Now.DayOfWeek != DayOfWeek.Sunday &&    // it's not sunday
                DateTime.Now.Hour>=8 && DateTime.Now.Hour < 17)   // it is 08:00 to 16:59
            {
                // work time
            }

答案 1 :(得分:-1)

DateTime start = new DateTime(2009, 12, 9, 10, 0, 0)); //10 o'clock
DateTime end = new DateTime(2009, 12, 10, 12, 0, 0)); //12 o'clock
DateTime now = DateTime.Now;

if ((now > start) && (now < end))
{
   //match found
}