Skip to content

Instantly share code, notes, and snippets.

@laxman954
Created September 11, 2014 14:22
Show Gist options
  • Save laxman954/b5f3779e28131218f9e2 to your computer and use it in GitHub Desktop.
Save laxman954/b5f3779e28131218f9e2 to your computer and use it in GitHub Desktop.
Format day like 1st,2nd,3rd.. in JSP
<%@ tag body-content="empty" trimDirectiveWhitespaces="true"%>
<%@ attribute name="day" required="true" type="String"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<fmt:parseNumber var="n" type="number" value="${day}" />
${day}
<sup>
<c:choose>
<c:when test="${n >= 11 && n <= 13}">th </c:when>
<c:when test="${n%10 == 1}">st </c:when>
<c:when test="${n%10 == 2}">nd </c:when>
<c:when test="${n%10 == 3}">rd </c:when>
<c:otherwise>th</c:otherwise>
</c:choose>
</sup>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment