Date format is converted to a string
// Convert the date to a string Date d=new Date(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String s=sdf.format(d); System.out.println(s); // convert a string to date Date d1=null; try { d1=sdf.parse(s); } catch (ParseException e) { e.printStackTrace (); } System.out.println(d1);