JS日期比较

function CompareDate(inputDate){
     var currentDate = new Date();
     if(currentDate.getYear() > inputDate.getYear())
       return -1;
     else if(currentDate.getYear() < inputDate.getYear())
       return 1;
    
     if(currentDate.getMonth() > inputDate.getMonth())
       return -1;
     else if(currentDate.getMonth() < inputDate.getMonth())
       return 1;
    
     if(currentDate.getDate() > inputDate.getDate())
       return -1;
     else if(currentDate.getDate() < inputDate.getDate())
       return 1;
    
     return 0;
    }
  
    function Compare() {
    var sday = document.getElementById("day").value.split('-');
     var inputDate = new Date(sday[0],sday[1]-1,sday[2]);
     if(isNaN(inputDate)){
       alert("不是日期");
    return;
     }
     var result = CompareDate(inputDate);
     if(result < 0)
       alert(inputDate.toLocaleString() + "小于当前日期");
     else if(result > 0)
       alert(inputDate.toLocaleString() + "大于当前日期");
     else
       alert(inputDate.toLocaleString() + "等于当前日期");
    }

posted on 2009-10-25 00:11 飞熊 阅读(2509) 评论(0)  编辑  收藏 所属分类: javaScript


只有注册用户登录后才能发表评论。


网站导航:
 
<2009年10月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

导航

统计

常用链接

留言簿(1)

随笔分类

随笔档案

文章分类

文章档案

收藏夹

搜索

最新评论

阅读排行榜

评论排行榜