js 的 当天,当月的第一天,最后一天


时间格式-当月当天

点击查看代码
function getFullTime() {
  var date = new Date()
  var Y = date.getFullYear()
  var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
  var D = (date.getDate() < 10 ? '0' + (date.getDate()): date.getDate())
  return Y + '-' + 'M' + '-' + D
  //   return Y + '-' + 'M' + '-01'
} 

时间格式-当月最后一天

点击查看代码
function getLastDay() {
  var date = new Date()
  var currentMonth = date.getMonth()
  var nextMonth = ++currentMonth
  var nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1)
  var oneDay = 1000 * 60 * 60 * 24
  var lastTime = new Date(nextMonthFirstDay - oneDay)
  var month = parent(lastTime.getMonth() + 1)
  var day = lastTime.getDate()
  if ( month < 10) {
    month = '0' + month
  }
  if (day < 10) {
    day = '0' + day
  }
  return date.getFullYear() + '-' + month + '-' + day 
}