aspose file tools
The moose likes JSP and the fly likes Date Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Date Problem" Watch "Date Problem" New topic
Author

Date Problem

barnali chakrabarty
Greenhorn

Joined: Dec 10, 2001
Posts: 7
Hi:
I use MySql as database and I need to retrieve a date field (in yyyy-mm-dd format) and show it in dd-mm-yyyy format as a String.Is it possible? Can anybody help please?
Codes will be welcome.
Thanks.
Andrew Obodoefuna
Greenhorn

Joined: Dec 03, 2001
Posts: 5
Assuming that you obtain the date from mySQL through a resultSet i.e. resultset.getDate(int), the java.util.Date object returned (date) can be parsed like so:
SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance();
format.applyPattern("dd-MM-yyyy");
String formattedDate = format.format(date);
You can perform this piece of code in your responding servlet or through a JSP taglib that takes in the java.util.Date as an argument in the JSP and performs the logic in its tag class.
For a decent datetime JSP taglib see: http://jakarta.apache.org/taglibs/doc/datetime-doc/intro.html
Alternatively you can easily write one yourself.
AO.

Pranit Saha
Ranch Hand

Joined: Sep 09, 2001
Posts: 130
You will get the answer in this thread.. It worked fine..
http://www.javaranch.com/ubb/Forum50/HTML/000351.html
Pranit..

Originally posted by barnali chakrabarty:
Hi:
I use MySql as database and I need to retrieve a date field (in yyyy-mm-dd format) and show it in dd-mm-yyyy format as a String.Is it possible? Can anybody help please?
Codes will be welcome.
Thanks.

 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Date Problem
 
Similar Threads
Date Validation
How to convert String to Date
conversion of date
How to fetch Date Field from excel sheet in Java
How to determine Data Format while we are getting Data from Excel Sheet