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 飛熊 閱讀(2533) 評論(0)  編輯  收藏 所屬分類: javaScript

          <2009年10月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導航

          統計

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 沙洋县| 满城县| 金川县| 深州市| 高清| 铜梁县| 金湖县| 临湘市| 静安区| 库尔勒市| 尉氏县| 达孜县| 天峻县| 鸡泽县| 伊金霍洛旗| 云龙县| 宜宾市| 怀集县| 湘乡市| 新建县| 定远县| 青浦区| 镇坪县| 东兰县| 金沙县| 瑞昌市| 财经| 灌阳县| 延寿县| 民乐县| 石棉县| 多伦县| 瓮安县| 永和县| 海南省| 蒙自县| 房山区| 永安市| 宜州市| 揭西县| 鹤山市|