zoukankan      html  css  js  c++  java
  • 获取当前时间前后6个月的时间数组

    我们公司有这么一个需求,不用时间插件,只获取当前时间前后6个月的数组,用下拉框来显示,多余的不说了。直接上代码:

    GetPreMonthDay: function () {
          //创建现在的时间
          let data = new Date();
          //获取年
          let year = data.getFullYear();
          let years = data.getFullYear();
          //获取月
          let mon = data.getMonth() + 1;
          let mons = data.getMonth() + 1;
          let arry = [];
          let list = [];
          let mon1 = mon, mon2 = mons,year1=year,year2=years;
          //获取前6个月的数组
          for (let i = 0; i < 7; i++) {
            mon1 = i == 0 ? parseInt(mon1) - 6 : parseInt(mon1) + 1;
            if (parseInt(mon1) <= 0) {
              year1 = parseInt(year1) - 1;
              mon1 = parseInt(mon1) + 12;
            } else if (parseInt(mon1) > 12) {
              year1 = parseInt(year1) + 1;
              mon1 = parseInt(mon1) - 12;
            }
            if (parseInt(mon1) < 10) {
              mon1 = "0" + mon1;
            }
            arry[i] = {
              name: year1 + "年" + mon1 + '月',
              value: year1 + '-' + mon1,
            };
          }
          //获取后6个月的数组
          for (let i = 0; i < 6; i++) {
            mon2 = parseInt(mon2) + 1;
            if (parseInt(mon2) > 12) {
              year2 = parseInt(year2) + 1;
              mon2 = parseInt(mon2) - 12;
            }
            if (parseInt(mon2) < 10) {
              mon2 = "0" + mon2;
            }
            list[i] = {
              name: year2 + "年" + mon2 + '月',
              value: year2 + '-' + mon2,
            };
          }
          let time = arry.concat(list);
          return time;
        },
  • 相关阅读:
    DailyRollingFileAppender的使用
    CSS自动换行
    MAC与WIN10电脑共享文件
    C++常用STL
    Python机器学习及实践 课后小题
    Mac上利用VScode配置c/c++开发环境
    pycharm+anaconda在Mac上的配置方法 2019.11.29
    二分查找 python实现
    python3相关
    算法图解 各部分回忆
  • 原文地址:https://www.cnblogs.com/mxyr/p/10323840.html
Copyright © 2011-2022 走看看