1.日期大小比较
<script> var beginDate=$("#beginDate").val(); var endDate=$("#endDate").val(); var d1 = new Date(beginDate.replace(/-/g, "/")); var d2 = new Date(endDate.replace(/-/g, "/")); if(beginDate!=""&&endDate!=""&&d1 >=d2) { alert("开始时间不能大于结束时间!"); return false; } </script>
2.增减天数
/** * 调整时间 * @param {any} date 时间 * @param {any} day 增减天数 */ function formatTime(date,day) { var now = date.split('-'); now = new Date(Number(now['0']), (Number(now['1']) - 1), Number(now['2'])) now.setDate(now.getDate() + day) var year = now.getFullYear(); var month = now.getMonth() + 1, month = month < 10 ? '0' + month : month; var day = now.getDate(), day = day < 10 ? '0' + day : day; return year + '-' + month + '-' + day; }