未来就是现在的延续,过去就是完成的现在

JS获取当前周

 var now = new Date()
 var weekFirstDay = new Date(now- (now.getDay() - 1) * 86400000)
 var firstMonth = Number(weekFirstDay.getMonth()) + 1
 var weekLastDay = new Date((weekFirstDay / 1000 + 6 * 86400) * 1000)
 var lastMonth = Number(weekLastDay.getMonth()) + 1
 var currentWeek = weekFirstDay.getFullYear() + '-' + firstMonth + '-' + weekFirstDay.getDate() + '~' + weekLastDay.getFullYear() + '-' + lastMonth + '-' + weekLastDay.getDate()

其中注意getYear()和getFullYear()的区别

posted @ 2018-01-24 22:20  lzj123  阅读(4003)  评论(0编辑  收藏  举报