js将毫秒转换为年月日时分秒(两种输出格式)

var sec=1588919434;
var time = new Date(sec*1000);
//style one
console.log(time.getFullYear()+"年"+":"+(time.getMonth()+1)+"月"+":"+time.getDate()+"日"+":"+time.getHours()+"点"+":"+time.getMinutes()+"分"+":"+
time.getSeconds()+"秒");
//style two
console.log(time.getFullYear()+"年"+"-"+(time.getMonth()+1)+"月"+"-"+time.getDate()+"日"+"-"+time.getHours()+"点"+"-"+time.getMinutes()+"分"+"-"+
time.getSeconds()+"秒");

你可能感兴趣的:(笔记)