从Java APIhttps://docs.oracle.com/javase/8/docs/api/java/util/Date.html
Date类表示特定的时间瞬间,精度为毫秒。
试着去理解的差异/连接
Date和
DateFormat。
public static void main(String [] args) throws ParseException{ String dateString = "2015-07-16 17:07:21"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // use SimpleDateFormat to define how to PARSE the INPUT Date date = sdf.parse(dateString); // at this point you have a Date-Object with the value of // 1437059241000 milliseconds // It doesn't have a format in the way you think // use SimpleDateFormat to define how to FORMAT the OUTPUT System.out.println( sdf.format(date) ); sdf = new SimpleDateFormat(); System.out.println( sdf.format(date) ); // ....}输出:(请注意,日期保持不变,只是其表示形式(格式)发生了变化)
2015-07-16 17:07:217/16/15 5:07 PM



