aspose file tools*
The moose likes Java in General and the fly likes java.sql.Date to 'dd-mm-yyyy' format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.sql.Date to Watch "java.sql.Date to New topic
Author

java.sql.Date to 'dd-mm-yyyy' format

sandeep Kumar
Ranch Hand

Joined: Sep 19, 2007
Posts: 41
Hi All,

Can any one help me with the code snippet for the following?

I am getting a java.sql.Date object from the data base. I wanted it to be converted into the format of 'DD-MM-YYYY' the return object may be either a Date object or a String.

Thanks in Advance. Immediate response would be highly appreciated.

Regards,
Sandeep.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Actually if you want something that's formatted as dd-mmm-yyyy it would have to be a String. A Date object doesn't have any format, it's just a date.

Anyway to produce that String you should create a SimpleDateFormat object with the appropriate parameters, then call its format(Date) method on your java.sql.Date.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

as Paul suggested SimpleDateFormat is the right solution to make your life easier.

see Java Doc to provide appropriate parameters in your SimpleDateFormat Object. or use Google to find an example.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
sandeep Kumar
Ranch Hand

Joined: Sep 19, 2007
Posts: 41
Hi Paul Clapham, Muhammad Saifuddin

Thanks a lot for the response.

Regards,
Sandeep.
vinnu kumar
Greenhorn

Joined: Sep 10, 2007
Posts: 12
Use SimpleDateFormat to set the format as you like..
DateFormat df=new SimpleDateFormat("dd-MMM-yyyy");
Date date=new Date();
String s=df.format(date);
System.out.println(s);
sandeep Kumar
Ranch Hand

Joined: Sep 19, 2007
Posts: 41
Hi Vinnu Kumar,

Thanks a lot for your response.

Regards,
Sandeep.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Hi Vinnu, Welcome to ranch,

Suggestion : Use UBB Code specially when you pasting a code on forum, This is useful for displaying programming code.

Thanks,
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java.sql.Date to 'dd-mm-yyyy' format