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();

  • 相关阅读:
    NYOJ 542 试制品(第五届河南省省赛)
    714-Card Trick
    716-River Crossing
    1248-海岛争霸
    51Nod
    51Nod
    NYOJ_1274_信道安全
    ZZNU 2095 : 我只看看不写题
    前端-HTML标签
    python 17篇 unittest单元测试框架
  • 原文地址:https://www.cnblogs.com/wssdx/p/12946047.html
Copyright © 2011-2022 走看看