js 获取当前时间并格式化

// 获取当前时间并格式化
export const getNowTime = () => {
    const time = new Date()
    let y = time.getFullYear()
    let m = time.getMonth()+1
    let d = time.getDate()
    let h = time.getHours()
    let mi = time.getMinutes()
    let s = time.getSeconds()
    m = m<10?`0${m}`:m
    d = d<10?`0${d}`:d
    h = h<10?`0${h}`:h
    mi = mi<10?`0${mi}`:mi
    s = s<10?`0${s}`:s
    return `${y}-${m}-${d} ${h}:${mi}:${s}`
}

 

posted @ 2019-08-21 14:31  拈花醉  阅读(2981)  评论(0)    收藏  举报