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.
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.
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);