1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
function calDates(dateVal, oper, days) { var dt = dateVal === null ? new Date() : new Date(dateVal.split("-")[0], dateVal.split("-")[1]-1, dateVal.split("-")[2]); var date = oper ? dt.getDate() + parseInt(days) : dt.getDate() - parseInt(days); dt.setDate(date); return dt.getFullYear() + "-" + formatDateNum(dt.getMonth() + 1) + "-" + formatDateNum(dt.getDate()); }
Date.prototype.format = function(date, seperator, seperatorTime) { var year = date.getFullYear(); var month = date.getMonth() + 1; var days = date.getDate(); var fmt = year + seperator + month + seperator + days; fmt = seperatorTime === null ? year + seperator + month + seperator + days : fmt + " " + date.getHours() + seperatorTime + date.getMinutes() + seperatorTime + date.getSeconds(); return fmt; }
function formatDateNum(num) { return num < 10 ? "0" + num : num; }
|