900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > js获取年月日 时分秒的日期格式

js获取年月日 时分秒的日期格式

时间:2021-10-09 06:09:20

相关推荐

js获取年月日 时分秒的日期格式

const date = new Date()const year = date.getFullYear()const month = date.getMonth() + 1 >= 10 ? date.getMonth() + 1 : `0${date.getMonth() + 1}`const day = date.getDate() >= 10 ? date.getDate() : `0${date.getDate()}`const hours = date.getHours() >= 10 ? date.getHours() : `0${date.getHours()}`const min = date.getMinutes() >= 10 ? date.getMinutes() : `0${date.getMinutes()}`const s = date.getSeconds() >= 10 ? date.getSeconds() : `0${date.getSeconds()}`const newDate = `${year}-${month}-${day} ${hours}:${min}:${s}`

js获取年月日 时分秒的日期格式,如:-05-06 10:00:08

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。