自学内容网 自学内容网

js快速转换时间(时间戳转换成年月日时分秒)

1:js转换

1728270833000 转换为  2024-10-07 11:13:53

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);
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

new Date(1728270833000).toLocaleString()

2:工具转换

day.js

dayjs(1728270833000).format('YYYY-MM-DD HH:mm:ss')

(记录下懒得使用工具时如何一行代码转换时间)


原文地址:https://blog.csdn.net/m0_72196169/article/details/142742277

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!