1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > js获取时间戳 将时间戳转换为年月日时分秒

js获取时间戳 将时间戳转换为年月日时分秒

时间:2019-09-19 17:30:18

相关推荐

js获取时间戳 将时间戳转换为年月日时分秒

一、js获取时间戳

// js获取当前时间戳(三种方式都可以)let time1 = new Date().getTime();let time2 = Date.now();let time3 = new Date().valueOf(); //valueOf返回 Date 对象的原始值console.log('time1:', time1)console.log('time2:', time2)console.log('time3:', time3)

二、时间戳转换为年月日时分秒

//将时间戳格式转换成年月日时分秒var date = new Date(time3);var Y = date.getFullYear() + '-';var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());var strDate = Y + M + D + h + m + s;console.log('输出内容:', strDate)

三、控制台输出内容

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