自定义格式日期

使用日期页面需导入包:

<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

自定义日期格式:

<fmt:formatDate value="${日期}" pattern="yyyy-MM--dd HH:mm:ss"/>

前端日期存入数据库成date日期需在使用日期的类中加载此方法:

@InitBinder
public void initBinder(WebDataBinder binder) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
dateFormat.setLenient(true);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
原文地址:https://www.cnblogs.com/zhangrongfei/p/11206696.html