格式化时间戳
1 timestampToTime(timestamp) { 2 const dt = new Date(timestamp * 1000) 3 const y = dt.getFullYear() 4 const m = (dt.getMonth() + 1 + '').padStart(2, '0') 5 const d = (dt.getDate() + '').padStart(2, '0') 6 7 const hh = (dt.getHours() + '').padStart(2, '0') 8 const mm = (dt.getMinutes() + '').padStart(2, '0') 9 const ss = (dt.getSeconds() + '').padStart(2, '0') 10 11 return `${y}-${m}-${d} ${hh}:${mm}:${ss}` 12 }
//2022-10-10 10:10:10
格式日期时间转换成时间戳
1 var time = '2020-10-1 01:01:01 2 var time1= (new Date(time)).getTime() / 1000 3 console.log(time1) 4 //十位时间戳 5 //不除以1000 则输出13位时间戳
标签:转换成,const,10,padStart,日期,格式,dt From: https://www.cnblogs.com/changshu/p/16774553.html