美文网首页
JS格式化时间格式方法

JS格式化时间格式方法

作者: 走的是前方的路_端的是生活的苦 | 来源:发表于2020-05-08 22:23 被阅读0次

/ 获取当前时间并进行格式化    2020-05-08 10:20:59

export const getNowTime = () => {

    const time = new Date()

    let year = time.getFullYear()

    let month = time.getMonth()+1

    let day = time.getDate()

    let hour = time.getHours()

    let min = time.getMinutes()

    let sec = time.getSeconds()

    month = month<10?`0${month}`:month

    day = day<10?`0${day}`:day

    hour = hour<10?`0${hour}`:hour

    min= min<10 ? `0${min}` : min

    sec= sec<10 ? `0${sec}` : sec

    return `${year}-${month}-${day} ${hour}:${min}:${sec}`

}

相关文章

网友评论

      本文标题:JS格式化时间格式方法

      本文链接:https://www.haomeiwen.com/subject/tihcnhtx.html