1

Please let me know how do I convert Epoch Time (example - 1355893200000) to mm/dd hh:mm AM/PM format in JSP.

Surabhi
  • 3,508
  • 2
  • 17
  • 12

3 Answers3

1

Solution 1 (three startDate keep same):

<jsp:useBean id="startDate" class="java.util.Date" />

<jsp:setProperty name="startDate" property="time" value="${record.startDate}"/>

<fmt:formatDate value="${startDate}" type="date" dateStyle="long"/>

Solution 2:

// item is long, don't pass testing, is EL support Date Type init Object??

<fmt:formatDate value="${Date(item)}" pattern="yyyy-MM-dd hh:mm:ss"/>

fmt:parseDate use SimpleDateFormat to parse Date from String. a Date could construct from Date date = new Date (Long.parase(epochString))

The JSP version usually goes hand in hand with the servlet version as follows:

Servlet 2.5 uses JSP 2.1 
Servlet 2.4 uses JSP 2.0 
Servlet 2.3 uses JSP 1.2 
Servlet 2.2 uses JSP 1.1 
Servlet 2.1 uses JSP 1.0 

maybe help:

reference:

jstl code repo

Mark Simon
  • 362
  • 4
  • 11
0

You could use JSTL Core fmt:formatDate Tag. More info http://www.tutorialspoint.com/jsp/jstl_format_formatdate_tag.htm

MAQ
  • 3
  • 4
-1

You can look at this for converting a unix timestamp to a Java Date object.

To format the date you can use SimpleDateFormat

E.g.

SimpleDateFormat format = new SimpleDateFormat("MM/dd hh:mm aaa");
String formatted = format.parse(myDate);
Community
  • 1
  • 1
micha
  • 47,774
  • 16
  • 73
  • 80