FreeKB - JSTL - date format
JSTL - date format

Home > Search


Near the beginning of your JSP page, use the fmt library.

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

 

Create a varialbe (now in this example) where the value is java.util.Date().

<c:set var="now" value="<%=new java.util.Date()%>" />

 

You can now format the date to your preference.

<fmt:formatDate pattern="yyyy-MM-dd" value="${now}" />

 

If you want to store the results in a variable, just add var.

<fmt:formatDate pattern="yyyy-MM-dd" value="${now}" var="todaysDate" />

 

Be aware that a date obtained from a SQL database will not be a java.util.Date() object and thus you must parse the date string.

<fmt:setLocale value="${requestLocale.locale}"/>
<fmt:parseDate pattern="yyyy-MM-dd" value="${title.date_updated}" var="parsedDate" />
<fmt:formatDate value="${parsedDate}" pattern="MMM dd, yyyy" />

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments