1:js转换
1728270833000 转换为 2024-10-07 11:13:53
javascript
var date = new Date(1728270833000); // 参数需要毫秒数,所以这里将秒数乘于 1000
Y = date.getFullYear() + '-';
M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
D = date.getDate() + ' ';
h = date.getHours() + ':';
m = date.getMinutes() + ':';
s = date.getSeconds();
document.write(Y+M+D+h+m+s);
javascript
new Date(1728270833000).toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' }).replace(/\//g, '-')
1728270833000 转换为 2024/10/07 11:13:53
javascript
new Date(1728270833000).toLocaleString()
2:工具转换
day.js
javascript
dayjs(1728270833000).format('YYYY-MM-DD HH:mm:ss')
(记录下懒得使用工具时如何一行代码转换时间)