My code is:
import java.text.*;
import java.util.Date;
public class DateEx {
public static void main(String[] args) {
//String valueFromDB = "2012/06/06 00:00:00";
String valueFromDB = "2012-12-31 00:00:00.0";
Date d = new Date(valueFromDB);
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
String dateWithoutTime = sdf.format(d);
System.out.println("sdf.format(d) " + dateWithoutTime);
}
}
It works for "2012/06/06 00:00:00" and I need to pass "2012-12-31 00:00:00.0" it is showing illegal argument. May be because I have use "-" in date or because of timestamp fraction second. I need date in dd-mm-yyyy format.
Try this –