时间比较

来源:互联网 发布:sql 00933 编辑:程序博客网 时间:2024/06/10 01:56
  1. <script   language="JavaScript"
  2. function  getInfo(a,b)
  3. {
  4.     
  5.     if(compare(a,b)){
  6.         alert("a>=b");
  7.     }else
  8.     {
  9.         alert("a<b");
  10.     }
  11. }
  12. function  compare(a,b)
  13. {
  14.     alert("a = "+a);
  15.     alert("b = "+b);
  16.     var time_a = a.split('-');
  17.     var time_b = b.split('-');
  18.     alert(time_a[0]);
  19.     if(parseInt(time_a[0])<parseInt(time_b[0]))
  20.     {
  21.         return false;
  22.     }
  23.     else if(parseInt(time_a[1])==parseInt(time_b[1]))
  24.     {
  25.         if (parseInt(time_a[1])<parseInt(time_b[1]))
  26.         {
  27.             return false;
  28.         }
  29.         else if(parseInt(time_a[1])==parseInt(time_b[1]))
  30.         {
  31.             if(parseInt(time_a[2])<=parseInt(time_b[2]))
  32.             {
  33.                 return false;
  34.             }
  35.         }
  36.     }
  37.     return true;
  38. }
  39. </script>
原创粉丝点击