zoukankan      html  css  js  c++  java
  • 日历封装

    getManthDate (year, month) {
            this.year = parseInt(year)
            this.month = parseInt(month)
            if (month === 13) {
              month = 1
              this.month = 1
              year += 1
              this.year += 1
            }
            if (month === 0) {
              month = 12
              this.month = 12
              year -= 1
              this.year -= 1
            }
            var tempArray = []
            var ret = []
            if (!year || !month) {
              var today = new Date()
              year = today.getFullYear()
              month = today.getMonth() + 1
              this.year = year
              this.month = month
            }
            var firstDay = new Date(year, month - 1, 1)
            var firstWeekDay = firstDay.getDay()
            firstWeekDay = firstWeekDay === 0 ? 7 : firstWeekDay
            var lastDayofLastMonth = new Date(year, month - 1, 0)
            var lastDateOfLastMonth = lastDayofLastMonth.getDate()
            var preMonthDayCount = firstWeekDay - 1
            var lastDay = new Date(year, month, 0)
            console.log('lastDay', lastDay)
            var lastDate = lastDay.getDate()
            for (let i = 0; i < 6 * 7; i++) {
              var date = i + 1 - preMonthDayCount
              var isActiveMonth = 1
              var showDate = date
              var thisMonth = month
              if (date <= 0) {
                isActiveMonth = 0
                thisMonth = month - 1
                showDate = lastDateOfLastMonth + date
              } else if (date > lastDate) {
                isActiveMonth = 2
                thisMonth = month + 1
                showDate = showDate - lastDate
              }
              thisMonth = thisMonth === 0 ? 12 : thisMonth
              thisMonth = thisMonth === 13 ? 1 : thisMonth
              tempArray.push({
                isAct: isActiveMonth,
                month: thisMonth,
                date: date,
                showDate: showDate
              })
            }
            for (let j = 0; j < tempArray.length; j += 7) {
              ret.push(tempArray.slice(j, j + 7))
            }
            this.days = ret
            if (!this.dateString) {
              this.selectedDate = new Date().getDate()
            } else {
              this.selectedDate = parseInt(this.dateString.split('-')[2])
            }
            console.log(this.days, 'days')
            console.log('selectedDate', this.selectedDate)
            console.log('year', this.year)
            console.log('month', this.month)
          }
    
  • 相关阅读:
    php安全模式笔记
    ./configure,make,make install的作用(转)
    composer自动载入类库的方式
    Specified key was too long; max key length is 1000 bytes
    海量数据中找出前k大数(topk问题)
    斐波那契数列n项的值。(递归和非递归算法Golang实现)
    基于Docker和Golang搭建Web服务器
    Nginx简单介绍以及linux下使用Nginx进行负载均衡的搭建
    php实现商城秒杀
    一致性hash (PHP)
  • 原文地址:https://www.cnblogs.com/langqq/p/9132090.html
Copyright © 2011-2022 走看看