zoukankan      html  css  js  c++  java
  • vue 获取字符串日期间的差值

     /**
       * 获取当前日期
       * @returns {string}
       * @Example getNowTime('-')
       */
      getNowTime(str){
        let nowDate = new Date();
        let y = nowDate.getFullYear();
        let m = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
        let d = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
        if(str){
          return y + str + m + str + d;
        }else{
          return y + '年' + m + '月' + d + '日';
        }
      },
    
      /**
       * 获取两个字符串日期间的差值
       * @param startDay
       * @param endDay
       * @Example getDifferentialValForDate('2020-01-05','2020-01-10')
       */
      getDifferentialValForDate(startDay,endDay){
        return Math.abs(parseInt((new Date(endDay).getTime() - new Date(startDay).getTime())/(1000 * 60 * 60 * 24)));
      },
    
      /**
       * 获取当前月份
       * @returns {string}
       * @Example getNowMonth('-')
       */
      getNowMonth(str){
        let nowDate = new Date();
        let y = nowDate.getFullYear();
        let m = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
        if(str){
          return y + str + m;
        }else{
          return y + '年' + m + '月';
        }
      },
    
      /**
       * 获取两个字符串月份间的差值
       * @param startMonth
       * @param endMonth
       * @Example getDifferentialValForMonth('2020-04','2020-01')
       */
      getDifferentialValForMonth(startMonth,endMonth){
        let startMonths = startMonth.split('-');
        let endMonths = endMonth.split('-');
        return Math.abs((parseInt(startMonths[0]) * 12 + parseInt(startMonths[1])) - (parseInt(endMonths[0]) * 12 + parseInt(endMonths[1])));
      },
    
  • 相关阅读:
    windows 设置nginx开机自启动
    vue js中解决二进制转图片显示问题
    oracle 各种问题
    Nginx安装及配置详解包括windows linux 环境
    AOP-切面是如何织入到目标对象中的
    AOP-通知-笔记
    AOP-方法拦截器-笔记
    JdkDynamicAopProxy-笔记
    Joinpoint继承体系-笔记
    AOP-Pointcut-笔记
  • 原文地址:https://www.cnblogs.com/maggieq8324/p/12701934.html
Copyright © 2011-2022 走看看