• vue获取当前日期以及当前日期为基点获取任何日期,超省事


    vue中获取当前日期
    很简单的 新建一个Date对象。
    var nowday = new Date();

    代码:

    let neWDay= nowday .getTime() + 1000 * 60 * 60 * 24 * 1
    

    这一块是以当前时间为基础往后一天,列如今天是2022-09-29, 那么neWDay的值就是2022-09-30的.getTime()。

    nowday.setTime(neWDay)
    那么此时的nowday就是 2022-09-30

    顾名思义:以2022-09-29为基础。

    let neWDay= nowday .getTime() + 1000 * 60 * 60 * 24 * (-1) 就是2022-09-28的Time
    let neWDay= nowday .getTime() + 1000 * 60 * 60 * 24 * 1 就是2022-09-30的Time

    那三十天钱的时间就是:

    let neWDay= nowday .getTime() + 1000 * 60 * 60 * 24 * (-30)
    

    获取到时间之后,我们在重新set到原来的nowday上。
    说的有点乱,让我自己看得, 需要的朋友直接复制粘贴代码就完事

    直接上代码:

    //用法: 直接调用getDay(day), 
    //  getDay(0) 当前日期,  getDay(-1) 前一天,   getDay(-30) 前30天, 
    //  getDay(1) 后一天     getDay(30) 后30天, 
    getDay(day) {
           var nowday = new Date();  //  获取到当前日期
           var targetday_milliseconds = nowday .getTime() + 1000 * 60 * 60 * 24 * day;
           nowday .setTime(targetday_milliseconds);
           var nYear = nowday.getFullYear();
           var nMonth = nowday.getMonth();
           var nDate = nowday.getDate();
           nMonth = this.perfectDay(tMonth + 1);
           nDate = this.perfectDay(tDate);
           return nYear+ "-" + nMonth + "-" + nDate ;
       },
       perfectDay(month) {   //  单位数的数字  前面补0
           var m = month;
           if (month.toString().length == 1) {
               m = "0" + month;
           }
           return m;
       },
    
  • 相关阅读:
    iOS - Runloop在实际开发中的应用
    Matlab写入nc文件遇到‘Start+count exceeds dimension bound (NC_EEDGE)‘问题的解决办法
    Python之切片
    java虚拟机常用工具
    面试学习总结
    Java中「Future」接口详解
    8月份补丁更新:微软修补了121个安全漏洞
    2022年已过半,得抓紧
    MySQL - B-树和B+树
    HCIA网络基础7-VRP和命令行基础
  • 原文地址:https://blog.csdn.net/weixin_45729937/article/details/127109335