2020-07-06 13:47:49 格式时间

//获取当前时间戳
var timestamp = Date.parse(new Date());
timestamp = timestamp / 1000;
console.log(“当前时间戳为:” + timestamp);

//获取当前时间  
var n = timestamp * 1000;
var date = new Date(n);
//年  
var Y = date.getFullYear();
//月  
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
//日  
var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
//时  
var h = date.getHours();
//分  
var m = date.getMinutes();
//秒  
var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();

let timer = Y + "-" + M + "-" + D + " " + h + ":" + m + ":" + s
console.log(timer)

你可能感兴趣的:(微信小程序,js)