Java中Date通过JSONObject转成JSON字符串之后,格式如下:
{
"id":"7f6cf29f22054b519cd6df297aec5f76",
"sn":"lyduss",
"lat":36.67173,
"lon":117.05193,
"bdLat":36.677786,
"bdLon":117.064579,
"addr":"",
"createTime":{"date":17,"day":3,"hours":16,"minutes":9,"month":6,"nanos":0,"seconds":23,"time":1563350963000,"timezoneOffset":-480,"year":119}
}
在前台通过如下方式格式化:
function timeFormatter(value, row, index) {
var t1 = new Date(value.time);
var month = t1.getMonth() + 1;
if (month < 10) {
month = '0' + month;
}
var day = t1.getDate();
if (day < 10) {
day = '0' + day;
}
var hour = t1.getHours();
if (hour < 10) {
hour = '0' + hour;
}
var min = t1.getMinutes();
if (min < 10) {
min = '0' + min;
}
var sec = t1.getHours();
if (sec < 10) {
sec = '0' + sec;
}
var t2 = t1.getFullYear() + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec;
return t2;
}