• js 获取当前时间的前一天,后一天


    new Date(new Date().getTime() - 24*60*60*1000); //前一天
    new Date(new Date().getTime() + 24*60*60*1000); //后一天

    var myDate=new Date('22021/12/30');

    console.log(myDate) //Thu Dec 30 22021 00:00:00 GMT+0800 (中国标准时间)

    myDate.setDate(myDate.getDate()-1);
    console.log(myDate) //Wed Dec 29 22021 00:00:00 GMT+0800 (中国标准时间)

     vue写法:

     1 /**
     2  * 日期格式化
     3  */
     4 export function dateFormat (date, format) {
     5   format = format || 'yyyy-MM-dd hh:mm:ss'
     6   if (date !== 'Invalid Date') {
     7     const o = {
     8       'M+': date.getMonth() + 1, // month
     9       'd+': date.getDate(), // day
    10       'h+': date.getHours(), // hour
    11       'm+': date.getMinutes(), // minute
    12       's+': date.getSeconds(), // second
    13       'q+': Math.floor((date.getMonth() + 3) / 3), // quarter
    14       S: date.getMilliseconds() // millisecond
    15     }
    16     if (/(y+)/.test(format)) {
    17       format = format.replace(RegExp.$1,
    18         (date.getFullYear() + '').substr(4 - RegExp.$1.length))
    19     }
    20     for (const k in o) {
    21       if (new RegExp('(' + k + ')').test(format)) {
    22         format = format.replace(RegExp.$1,
    23           RegExp.$1.length === 1 ? o[k]
    24             : ('00' + o[k]).substr(('' + o[k]).length))
    25       }
    26     }
    27     return format
    28   }
    29   return ''
    30 }

     调用方式:

     import { dateFormat } from '@/utils/date'

    const startT = dateFormat(item.value[0],'yyyy-MM-dd')
     
     
    dateFormat(new Date(new Date().getFullYear() ,0),'yyyy-MM-dd')//当前年份的第一天
    dateFormat(new Date(new Date().getFullYear() + 1, 0, 0),'yyyy-MM-dd')//当前年份的最后一天
     
    如图:
  • 相关阅读:
    TCP
    关系型数据库基础
    spark教程(16)-Streaming 之 DStream 详解
    spark教程(15)-Streaming
    灰度图Matlab
    mesh函数
    axis函数
    Matlab提供了两种除法运算:左除()和右除(/)
    基和时间平移矩阵
    转载:实现MATLAB2016a和M文件关联
  • 原文地址:https://www.cnblogs.com/time1997/p/14867666.html
Copyright © 2020-2023  润新知