获取时间戳的方法并转化成Y-M-D h:m:s形式

JavaScript 获取时间戳 :
Math.round(new Date() / 1000)
比如
=1558081162
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() < 10 ? ‘0’ + date.getHours() : date.getHours()) + ‘:’;
var m = (date.getMinutes() < 10 ? ‘0’ + date.getMinutes() : date.getMinutes()) + ‘:’;
var ztime = Y+M+D+h+m+s
=2019-05-17 16:19:22

你可能感兴趣的:(javascript,函数)