System.DateTime theDay = 
                 new System.DateTime(System.DateTime.Today.Year, 7, 28);
            
         int compareValue;
         try {
            compareValue = theDay.CompareTo(System.DateTime.Today);
         } 
         catch (ArgumentException) {
            System.Console.WriteLine("Value is not a DateTime");
            return;
         }         if (compareValue < 0) {
            System.Console.WriteLine("{0:d} is in the past.", theDay);
         } 
         else if (compareValue == 0) {
            System.Console.WriteLine("{0:d} is today!", theDay);
         }
         else if (compareValue == 1) {
            System.Console.WriteLine("Value is null");
         }
         // compareValue > 0 && compareValue != 1
         else { 
            System.Console.WriteLine("{0:d} has not come yet.", theDay);
         }

解决方案 »

  1.   

    可以直接比较吧
    就用<或是>来比较吧,没试...
      

  2.   

    例如: 我取得当前时间string str=System.DateTime.Now.ToLongTimeString()串,  我做一个判断
    if(str>=07:50:00&&str<=11:45:00)
      {
         //所要执行的程序
       }
    当然啦,上面的语句是错的,我就想知道,如何经过转变可以成以上形状,使 得通过时间的判断来执行相应的程序!谢谢
      

  3.   

    if(Now >= Now.Date.AddHours(7).AddMinutes(50) And Now <= Now.Date.AddHours(11).AddMinutes(45))
      {
         //所要执行的程序
       }