/** * 比较两个日期大小,日期格式为yyyy-MM-dd HH:mm:ss */function dateCompare(startDate, endDate) { var start = new Date(startDate).getTime(); var end = new Date(endDate).getTime(); if (end >= start) { return true; } return false;}/** * 格式化当前日期为yyyy-MM-dd HH:mm:ss */function getNowFormatDate() { var date = new Date(); var year = date.getFullYear(); //获取完整的年份(1970开始) var month = date.getMonth() + 1;//获取当月(0-11) var strDate = date.getDate(); //获取当天(1-31) if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } return year + "-" + month + "-" + strDate + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();}/** * 将毫秒转换为指定格式的日期 */function format(time) { var t = new Date(time); var format = "yyyy-MM-dd HH:mm:ss"; var tf = function (i) { return (i < 10 ? '0' : '') + i }; return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) { switch (a) { case 'yyyy': return tf(t.getFullYear()); break; case 'MM': return tf(t.getMonth() + 1); break; case 'mm': return tf(t.getMinutes()); break; case 'dd': return tf(t.getDate()); break; case 'HH': return tf(t.getHours()); break; case 'ss': return tf(t.getSeconds()); break; } })}