In my web application I am currently using a custom DateUtil class to convert java.util.Date to String and vice versa. I am doing this only to convert to a default pattern dd/MM/YYYY. This is the only date format the entire application needs. Now there are lot of input fields, where date values are selected using a calender. I am currently converting this String value to java.util.Date using the DateUtil package before posting to database and then while displaying this date in jsp I am using jstl <fmt:formateDate> tag to convert format to dd/MM/YYYY.
Is there any way that I can set a default date pattern for the web-application. Atleast new Date().toString() should get printed in default(dd/MM/YYYY) format.
If I understood correctly, this is the way it goes now:
server as a String through a form
field.
object (I’m guessing you do it with
SimpleDateFormat or similar).
back to the user as a string,
formatted with JSTL tags.
And you want it to go something like this:
I’d say these are nearly similar in effort, but I’d also be inclined to use the JSTL formatter when displaying the dates.
I’d suggest that you stay with your current implementation. Just move your default date pattern to a class as a constant:
And use it with the formatting: