demo('2020-10-10 11:01') // => 2020-10-10 11:10
demo('2020-10-10 11:20') // => 2020-10-10 11:20
demo('2020-10-10 11:59') // => 2020-10-10 12:00
demo('2020-12-31 23:50') // => 2020-12-31 23:50
demo('2020-12-31 23:59') // => 2021-01-01 00:00
function demo (timeStr) {
timeStr = timeStr.replace(/-/g, '/')
var oDate = new Date(timeStr)
var stamp = oDate.getTime()
var minute = oDate.getMinutes()
var last = minute%10
if(last) {
stamp += (10-last) * 60 * 1000
}
oDate = new Date(stamp)
var t = {
year: pad_2_0(oDate.getFullYear()),
month: pad_2_0(oDate.getMonth() + 1),
day: pad_2_0(oDate.getDate()),
hour: pad_2_0(oDate.getHours()),
minute: pad_2_0(oDate.getMinutes()),
second: pad_2_0(oDate.getSeconds())
}
var res = t.year + '-' + t.month + '-' + t.day + ' ' + t.hour + ':' + t.minute;
console.log(timeStr, '=>', res)
return res;
}
function pad_2_0 (num) {
return num >= 10 ? num : '0' + num
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…