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)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 彭水| 内江市| 通河县| 泰来县| 佛坪县| 左云县| 宣威市| 垦利县| 乃东县| 罗江县| 故城县| 公安县| 区。| 衡阳市| 穆棱市| 湘潭市| 兴国县| 临颍县| 个旧市| 同仁县| 丰台区| 辽宁省| 大名县| 金塔县| 东兴市| 卫辉市| 新巴尔虎左旗| 九江县| 黎城县| 乐昌市| 通榆县| 当雄县| 颍上县| 芦山县| 化隆| 怀宁县| 绥阳县| 西乌| 开封县| 元阳县| 正安县|