zoukankan      html  css  js  c++  java
  • JS格式化日期, 今天/明天的日期

    // 时间戳转时间格式
    export const getTime = (dateTime = '') => {
        let time = ""
        let now = dateTime ? new Date(dateTime) : new Date()
        let year = now.getFullYear() //年份
        let month = now.getMonth() //月份
        let date = now.getDate() //日期
        month = month + 1
        if (month < 10) month = "0" + month
        if (date < 10) date = "0" + date

        return time = `${year}-${month}-${date}`
    }

    // 标准时间改字符串格式
    export const getStringTime = (dateTime) => {
        let date = new Date(dateTime)
        let yyyy = date.getFullYear()
        let mm = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
        let dd = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
        return yyyy + '-' + mm + '-' + dd;
    }
     
     

    //今天的日期
    var today = new Date();
    today.setTime(today.getTime());
    var todayStr = today.getFullYear()+"-" + (today.getMonth()+1) + "-" + today.getDate();
    //明天的日期
    var tomorrow = new Date();
    tomorrow.setTime(tomorrow.getTime() + 24*60*60*1000);
    var tomorrowStr = tomorrow.getFullYear()+"-"+(tomorrow.getMonth()+1)+"-"+tomorrow.getDate();

  • 相关阅读:
    阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:8. 委托事件
    阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:7. 服务调用
    Git
    Git
    Git
    Git
    Git
    Git
    Git
    Delphi
  • 原文地址:https://www.cnblogs.com/wssdx/p/12946047.html
Copyright © 2011-2022 走看看