创建日历

2020-08-03  本文已影响0人  AAA前端
var getDate = function (year, month) {
  var ret = []
  var firstDay = new Date(year, month - 1, 1)
  var firstDayWeekDay = firstDay.getDay()
  var premonthDayCount = firstDayWeekDay

  for (var i = 0; i < 7 * 6; i++) {
    var date = i + 1 - premonthDayCount
    var showDate = (new Date(year, month - 1, date)).getDate()
    var thisMonth = (new Date(year, month - 1, date)).getMonth() + 1
    var thisWeek = (new Date(year, month - 1, date)).getDay()

    ret.push({
      month: thisMonth,
      date: showDate,
      week: thisWeek
    })
  }
  return ret
}
上一篇下一篇

猜你喜欢

热点阅读