java返回json数据日期为一串数字字符串 js 转义

时间:2022-03-18 14:42:14

var time = "2514484555"; //这只是事例,并不是实际的数据

function timeToString(time) {
var datetime = new Date();
datetime.setTime(time);
var year = datetime.getFullYear();
var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1)
: datetime.getMonth() + 1;
var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime
.getDate();
var hour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime
.getHours();
var minute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes()
: datetime.getMinutes();
var second = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds()
: datetime.getSeconds();
return year + "-" + month + "-" + date;
}