var time = 1572080091;
var date = new Date(time * 1000);
var date = new Date();
var dt = date.getFullYear() + "-"
+ (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)) + "-"
+ (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + " "
+ (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ":"
+ (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ":"
+ (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
时间转换秒
var date = new Date("2018-11-20 18:08:00");
var time = date.getTime()/1000;//转换成秒;
moment
npm install moment --save
// 毫秒初始化 '2019-10-26 16:54:50'
var day = moment(1572080090000).format('YYYY-MM-DD');
// 秒初始化
var day = moment.unix(1572080205).format('YYYY-MM-DD');
// 多种格式匹配
moment("12-25-1995", ["MM-DD-YYYY", "YYYY-MM-DD"]);