Dinup Kandel Dinup Kandel - 1 year ago 142
Java Question

need to show date in yyyy/mm/dd format in java

I am using

Nebulla DateChooserCombo
. I have used it as
. It is Producing the result like 7/31/2011 which is in
format. I need the result in
format. For that I have use the code as.

DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String s = df.format(dateChooserFrom.getText());

But when I run the code it says
Cannot format given Object as a Date
. so please anybody could help me on this. I am using eclipse rcp and java.

Answer Source
DateFormat dffrom = new SimpleDateFormat("M/dd/yyyy");
DateFormat dfto = new SimpleDateFormat("yyyy-MM-dd");  
Date today = dffrom.parse("7/1/2011");
String s = dfto.format(today);

Convert the String to Date first.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download