File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Date Formatting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Date Formatting" Watch "Date Formatting" New topic

Date Formatting

vjy chin
Ranch Hand

Joined: Feb 17, 2005
Posts: 279

I am getting date from the resultset. So the default value will ne yyyy-MM-dd. but I need the date formatted into MM/dd/yyyy. SInce I need to assign the Date value in the return object that I need to display in the jsp. I need it as a Date because I need to sort the values according to the user input.

I tried doing this, but was not successful. I know, we can change to String to Date and vice-versa, but Date to format into another date, I was not able to do it.

Any help would be greatly appreciated.

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Just get the date from the ResultSet and don't format it into text just yet. Then, in the JSP, use the fmt:formatDate tag to display it in any format you like.
vjy chin
Ranch Hand

Joined: Feb 17, 2005
Posts: 279
Thanks Paul.

Actually I am using display:table tag to display all the tables. So I cannot use fmt:formatDate tag there.

As of now I am displaying it in the yyyy-MM-dd format, and I am able to sort properly also. I will still work and try to figure out a way to use formatting in the display:table tag.

I agree. Here's the link:
subject: Date Formatting
jQuery in Action, 3rd edition