龙空技术网

JS格式化时间格式方法

字里行间LM 224

前言:

眼前各位老铁们对“js的时间格式”大约比较关注,大家都想要剖析一些“js的时间格式”的相关内容。那么小编在网络上搜集了一些对于“js的时间格式””的相关文章,希望大家能喜欢,各位老铁们一起来学习一下吧!

// 获取当前时间并进行格式化    2020-05-08 10:20:59export 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的时间格式