Is it possible to change default formatting of Date object in JPS pages? Now I have some kind of formatting and I would like to change formatting without using fmt-tags, because that would mean I would have to type that formatting to all pages and there are many!
As per my knowledge, it is not possible as JSP will just invoke toString method on the object which you cannot override using settings. You have to do it manually.
without using fmt-tags
Best is to create your own custom taglib which does exactly the same as JSTL fmt:formatDate
.
But why would you want to reinvent the wheel? Is it the "much" effort of replacing the code in JSP? Well, that's just your job :) It's basically as simple as following:
- Drop jstl-1.2.jar in
/WEB-INF/lib
. Declare
fmt
taglib in top of your JSP:<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
Use
fmt:formatDate
on any bean'sjava.util.Date
property.<fmt:formatDate value="${bean.date}" type="date" dateStyle="short" />
Above example will print today's date as
10/01/25
for English locales and for example25.01.10
for German locales. No worries anymore! :)
You would be almost already finished in the time you spent asking the question and waiting the answer ;)