将时间戳转化为日期格式
程序员文章站
2022-03-27 17:11:26
...
代码如下
export function change(date) {
//date是整数,否则要parseInt转换
let time = new Date(date);
let y = time.getFullYear();
let m = time.getMonth()+1;
let d = time.getDate();
let h = time.getHours();
let mm = time.getMinutes();
let s = time.getSeconds();
return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
}
function add0(m){return m<10?'0'+m:m }