1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > js——根据时间戳转换为日期格式

js——根据时间戳转换为日期格式

时间:2021-06-15 09:45:18

相关推荐

js——根据时间戳转换为日期格式

function timestampToTime(timer){let curDate = new Date(timer * 1000);let Y = curDate.getFullYear();let M = curDate.getMonth() + 1 < 10 ? `0${curDate.getMonth() + 1}` : `${curDate.getMonth() + 1}`;let D = curDate.getDate() < 10 ? `0${curDate.getDate() + 1}` : `${curDate.getDate() + 1}`;let H = curDate.getHours() < 10 ? `0${curDate.getHours() + 1}` : `${curDate.getHours() + 1}`;let Min = curDate.getMinutes() < 10 ? `0${curDate.getMinutes() + 1}` : `${curDate.getMinutes() + 1}`;let S = curDate.getSeconds() < 10 ? `0${curDate.getSeconds() + 1}` : `${curDate.getSeconds() + 1}`;return `${Y}-${M}-${D} ${H}:${Min}:${S}`}console.log(timestampToTime(1632493838))

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