在String类型转Date类型或者Calendar类型时,如果String的日期格式不对,在转换过程中不会报错。
例如:String类型的时间是:2019-02-29
String str3 = "2019-02-29";
Date date3 = simple.parse(str3);
//Date类型输出:2019-03-01
String str4 = simple.format(date3);
System.out.println("Date:"+str4);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date3);
//Calendar类型输出:2019:2:1
System.out.println("Calendar:"+calendar.get(Calendar.YEAR)+":"+calendar.get(Calendar.MONTH)+":"+calendar.get(Calendar.DAY_OF_MONTH));