Date.prototype.format = function (format) {
var format = format || 'YYYY-MM-DD hh:mm:ss'
var d = this
var obj = {
YYYY: d.getFullYear(),
MM: d.getMonth() + 1,
DD: d.getDate(),
hh: d.getHours(),
mm: d.getMinutes(),
ss: d.getSeconds()
}
for (var i in obj) {
obj[i] = (obj[i] < 10) ? ('0' + obj[i]) : ('' + obj[i])
format = format.replace(i, obj[i])
}
return format
}
获取两个日期之间的天数
function dateDiffIncludeToday (startDateString, endDateString) {
let separator = '-' // 日期分隔符
let startDates = new Date(startDateString).format('YYYY-MM-DD').split(separator)
let endDates = new Date(endDateString).format('YYYY-MM-DD').split(separator)
let startDate = new Date(startDates[0], startDates[1] - 1, startDates[2])
let endDate = new Date(endDates[0], endDates[1] - 1, endDates[2])
return parseInt(Math.abs(endDate - startDate) / 1000 / 60 / 60 / 24) + 1// 把相差的毫秒数转换为天数
}
获取指定日期的后一天
function getNextDay (d) {
let format = 'YYYY-MM-DD'
d = new Date(d)
d = +d + 1000 * 60 * 60 * 24
d = new Date(d)
var obj = {
YYYY: d.getFullYear(),
MM: d.getMonth() + 1,
DD: d.getDate()
}
for (var i in obj) {
obj[i] = (obj[i] < 10) ? ('0' + obj[i]) : ('' + obj[i])
format = format.replace(i, obj[i])
}
return format
}
日期处理日期格式化获取两个日期之间的天数获取指定日期的后一天日期格式化Date.prototype.format = function (format) { var format = format || 'YYYY-MM-DD hh:mm:ss' var d = this var obj = { YYYY: d.getFullYear(), MM: d.getMon...