版权声明:作者: 阿顾, 转载请写明出处, 谢谢 https://blog.csdn.net/u010452388/article/details/80953945
步骤
1.pom.xml引入依赖
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
</dependency>
2.导入标签库到jsp页面
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
3.调用formateDate
<fmt:formatDate value="${user.birthday}" pattern="yyyy-MM-dd HH:mm:ss"/>
value:后台传递过来的数据
pattern:我们想要的格式
代码和结果
代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="/css/user.css" />
</head>
<body>
<table id="customers">
<tr>
<th>编号</th>
<th>用户名</th>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
<th>出生日期</th>
<th>创建时间</th>
<th>更新时间</th>
</tr>
<c:forEach items="${users}" var="user">
<tr>
<td>${user.id}</td>
<td>${user.userName}</td>
<td>${user.name}</td>
<td>${user.age}</td>
<td>
<c:choose>
<c:when test="${user.sex==1}">男</c:when>
<c:otherwise>女</c:otherwise>
</c:choose>
</td>
<td>
<fmt:formatDate value="${user.birthday}" pattern="yyyy-MM-dd HH:mm:ss"/>
</td>
<td>
<fmt:formatDate value="${user.created}" pattern="yyyy-MM-dd HH:mm:ss"/>
</td>
<td>
<fmt:formatDate value="${user.updated}" pattern="yyyy-MM-dd HH:mm:ss"/>
</td>
</tr>
</c:forEach>
</table>
</body>
</html>
结果展示