java后台时间没有格式化,返回时间戳,前端页面上 ${ data } 可通过 JSTL 的 fmt 标签来格式化:
引入JSTL库
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
日期格式化
<span class="pull-right">
时间:
<fmt:formatDate value="${s.date}" pattern="yyyy年MM月dd日HH点mm分ss秒" />
</span>
后台返回时间:
2020-09-24T11:07:00.000+00:00
// 日期数据 格式化
function addZero(num) {
return num < 10 ? '0' + num : num;
}
function formatDateTime(date) {
const time = new Date(Date.parse(date));
time.setTime(time.setHours(time.getHours() ));
// time.setTime(time.setHours(time.getHours() + 8));
const Y = time.getFullYear() + '-';
const M = this.addZero(time.getMonth() + 1) + '-';
const D = this.addZero(time.getDate()) + ' ';
const h = this.addZero(time.getHours()) + ':';
const m = this.addZero(time.getMinutes()) + ':';
const s = this.addZero(time.getSeconds());
return Y + M + D + h + m + s;
}
调用
formatDateTime(row.date)
页面显示: 2020-09-24 11:07:00