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;
        },
  • 相关阅读:
    性能问题分析-OOM内存溢出
    JVM介绍及参数配置
    性能问题分析-CPU偏高
    性能测试常见术语浅析
    性能测试中TPS上不去的几种原因浅析
    MyBatis拦截器:给参数对象属性赋值
    springboot读取配置文件的顺序
    ElasticSearch中文分词
    springboot和ELK搭建配置详情
    java命令行介绍
  • 原文地址:https://www.cnblogs.com/mxyr/p/10323840.html
Copyright © 2011-2022 走看看