獲取上個月

weixin_33866037發表於2018-09-12
function getPreDate () {
  const toDate = new Date()
  const preDay = toDate - 24 * 60 * 60 * 1000
  const preDate = new Date(preDay)
  return `${preDate.getFullYear()}-${(preDate.getMonth() + 1) > 9 ? preDate.getMonth() + 1 : '0' + (preDate.getMonth() + 1)}-${(preDate.getDate()) > 9 ? preDate.getDate() : '0' + (preDate.getDate())}`
}

相關文章