Since the java.util.Date
object stores Date as 2014-01-24 17:33:47.214
, but I want the Date format as 2014-01-24 17:33:47
. I w
Just for the record, the accepted answer given at the post you linked works:
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("S");
Date d = new Date();
System.out.println(df.format(d));
Calendar c = Calendar.getInstance();
c.set(Calendar.MILLISECOND, 0);
d.setTime(c.getTimeInMillis());
System.out.println(df.format(d));
}