• 周计划获取周日历


    根据windows日历,获取当前周,以及当前周的前2周和后4周,共7周的日期范围

    export function getFormatDate(serverDate) {
      let list = [] // 二维数组
      let formatDate = function (date, days) {
        let year = date.getFullYear()
        let month = date.getMonth() + 1
        let day = date.getDate()
        month = month < 10 ? '0' + month : month
        day = day < 10 ? '0' + day : day
        // let week = day === 7 ? 1 : parseInt(day / 7) + 1
        return days + year + '.' + month + '.' + day
      }
      let getFormatDay = function (date) {
        let month = date.getMonth() + 1
        month = month < 10 ? '0' + month : month
        let day = date.getDate()
        let week = day === 7 ? 1 : parseInt(day / 7) + 1
        return `${month}月第${week}周`
      }
      let addDate = function (date, n) {
        date.setDate(date.getDate() + n)
        return date
      }
      let setDate = function (date) {
        let week = date.getDay() === 0 ? 6 : date.getDay() - 1
        date = addDate(date, week * -1)
        let arr = []
        let day = getFormatDay(date)
        for (let i = 0; i < 7; i++) {
          arr.push(formatDate(i === 0 ? addDate(date, 0) : addDate(date, 1), day))
        }
        // console.log(arr);
        list.push(arr)
      }
      let algo = [-2, -1, 0, 1, 2, 3, 4]
      for (let i = 0; i < algo.length; i++) {
        setDate(
          addDate(serverDate ? new Date(serverDate) : new Date(), algo[i] * 7)
        )
      }
      // 处理成需要的结果
      let result = []
      list.forEach((item) => {
        item =
          item[0] +
          '-' +
          item[item.length - 1].substring(
            item[item.length - 1].length - 10,
            item[item.length - 1].length
          )
        result.push(item)
      })
      return result
    }

    结果:

  • 相关阅读:
    curl: (1) Protocol 'http not supported or disabled in libcurl
    线程-分为两类-用户线程和守护线程
    laypage分页插件的使用
    uploadify上传图片插件的使用
    redis安装
    php连接测试memcached
    pageY、clientY、screenY、offsetY的区别
    audio和video样式兼容
    实现剪切和复制功能
    滚动条样式
  • 原文地址:https://www.cnblogs.com/wuqilang/p/15193633.html
Copyright © 2020-2023  润新知