原生js实现方法
就是将要转换的时间用new Date()重新生成一个时间,然后分别获取年月日时分秒(或者你需要的格式)重新拼接返回就行
function changeTime(time){
let now = new Date(time),
Y = now.getFullYear(),
M = now.getMonth()+1,
D= now.getDate(),
h = now.getHours(),
m = now.getMinutes(),
s = now.getSeconds();
M = M<10?'0'+M:M;
D = D<10?'0'+D:D;
h = h<10?'0'+h:h;
m = m<10?'0'+m:m;
s = s<10?'0'+s:s;
return Y+'-'+M+'-'+D+' '+h+':'+m+':'+s;
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。