moment().startOf('day')// 当天零点
moment().subtract(1,'days').startOf('day')// 昨天零点
还有你这为啥过1秒才叫零点?
你好,两个时间戳比较简单,new两个当前date对象,将时、分,分别设置为零点和23:59分,再gettime就可以了。只接代码:
var zero = new date()
var eleven = new date()
zero.sethours(0)
zero.setminutes(0)
zero.setseconds(0)
eleven.sethours(23)
eleven.setminutes(59)
eleven.setseconds(0)
console.log('今天零点:' + zero.gettime())
console.log('23:59:' + eleven.gettime())希望解决了你的问题,如有疑问可追问!
// 今天var today = new Date()
today.setHours(0)
today.setMinutes(0)
today.setSeconds(0)
today.setMilliseconds(0)
alert(today)
var oneday = 1000 * 60 * 60 * 24
// 昨天
var yesterday = new Date(today - oneday)
alert(yesterday)
// 上周一
var lastMonday = new Date(today- oneday * (today.getDay() + 6))
alert(lastMonday)
// 上个月1号
var lastMonthFirst = new Date(today - oneday * today.getDate())
lastMonthFirst = new Date(lastMonthFirst - oneday * (lastMonthFirst.getDate() - 1))
alert(lastMonthFirst)