js比较两个时间的大小

时间格式:例2009-6-17,2009-6-18

    function opinionStartTimeEndTime( stratTime , endTime )

     {

      var strat = stratTime.split( "-" );

      var end = endTime.split( "-" );

       var sdate=new Date(strat[0],strat[1],strat[2]);

       var edate=new Date(end[0],end[1],end[2]);

       if(sdate.getTime()>edate.getTime())

       {

         return false;

       }

       return true;

     }

 

这样也行

function opinionStartTimeEndTime( stratTime , endTime )

     {

        var arr1=stratTime .split("-");

         var arr2=endT.endTime ("-");

                 if((stratTime == '' & endTime != '') || (stratTime != '' && endTime == ''))

         {

                 return false;

        }

        var a1;

         var a2;

         try

         {

                 a1=new Date(arr1[0],arr1[1],arr1[2]);

                 a2=new Date(arr2[0],arr2[1],arr2[2]);

                        if(a1>a2)

                         {

                             return false;

                        } 

          }

         catch(e)

         {

                 return false;

         }

你可能感兴趣的:(js)