convert timestamp value in EL to date time in jsp

2019-02-16 02:00发布

  2014-02-26 18:27:24

jsp page

 <html>

 timestamp is : ${timestamp}

 Date is : <b> date   </b>  //display date

 Time is : <b> time   </b>  //display time

 </html>

how to convert date and time from timestamp (EL)?

标签: jsp jstl el
1条回答
啃猪蹄的小仙女
2楼-- · 2019-02-16 02:32

You can use JSP Standard Tag Library Formatting Tags that provides a set of tags for parsing and formatting locale-sensitive numbers and dates.

If you have Date String then parse it into Date Object.

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

<c:set value="2014-02-26 18:27:24" var="dateString" />

<fmt:parseDate value="${dateString}" var="dateObject"
                pattern="yyyy-MM-dd HH:mm:ss" />

Date is : <b><fmt:formatDate value="${dateObject }" pattern="dd/MM/yyyy" /></b>
Time is : <b><fmt:formatDate value="${dateObject }" pattern="hh:mm a" /></b>

If you have time in milliseconds then convert in into Date Object.

<jsp:useBean id="dateObject" class="java.util.Date" />
<jsp:setProperty name="dateObject" property="time" value="${timeInMilliSeconds}" />

Date is : <b><fmt:formatDate value="${dateObject }" pattern="dd/MM/yyyy" /></b>
Time is : <b><fmt:formatDate value="${dateObject }" pattern="hh:mm a" /></b>

output:

Date is : 26/02/2014 Time is : 06:27 PM

查看更多
登录 后发表回答