获取当前时间戳(精确到秒):new Date(new Date()).getTime()
获取当天零点时间戳(00:00:00):new Date(new Date().toLocaleDateString()).getTime()
// 修改日期格式
function getDateTime(d) {
var year = d.getFullYear()
var month = d.getMonth() + 1
var date = d.getDate()
var hour = d.getHours()
var min = d.getMinutes() // 获取当前分钟数(0-59)
var sec = d.getSeconds()
return year + '-' + month + '-' + date + ' ' + hour + ':' + min + ':' + sec
}
let date1 = new Date(new Date().toLocaleDateString())
let date2 = new Date(new Date())
let a = getDateTime(date1)
let b = getDateTime(date2)
console.log(a) //0:0:0
console.log(b) //15:13:56
网友评论