js判斷兩個日期跨度小於3個月


1.

var startDate = $("#sysPriceDateFrom").val();
    var endDate = $("#sysPriceDateTo").val();
    var start  = new Date(startDate.replace(/-/g,"/")).getTime();
    var end = new Date(endDate.replace(/-/g,"/")).getTime();
    if(startDate == "" || startDate == null){
           return alert("請輸入報價日期(起)!");
       }else if(endDate == "" || endDate == null){
           return alert("請輸入報價日期(止)!");
       }else if(startDate >= endDate){
           return alert("\"起始時間\" 不能大於 \"截止時間\"哦!");
       }else if(end - start  > 3*30*24*60*60*1000 ){
           return alert("時間區間在 \"90天內\"哦!");
       }else{}

 

replace(/-/g,"/")---->格式化日期,如 2021-01-26  格式化為 2021/01/26 js 可以直接操作這個時間
/g 代表全局,所有的- 都替換

end - start  > 3*30*24*60*60*1000如果要精確,考慮年份是否為運年,月份135781012--31天,2--28、29,啊啊啊好麻煩

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM