java 8 日期api
//localdatetime -> string LocalDateTime now = LocalDateTime.now(); String format = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")); System.out.println(format); //date和localdatetime转换依靠instant中间 LocalDateTime.ofInstant(new Date().toInstant(), ZoneId.systemDefault());//date -> localdatetime Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant());//localdatetime -> date LocalDate parse = LocalDate.parse("2017-01-05"); System.out.println(parse); LocalTime parse2 = LocalTime.parse("12:12:12"); System.out.println(parse2); //datetimeformatter有严格的大小写区分HH是24小时制度hh是12小时制度 LocalDateTime parse3 = LocalDateTime.parse("2017-01-0512:12:12",DateTimeFormatter.ofPattern("yyyy-MM-ddHH:mm:ss")); System.out.println(parse3); LocalDateTime.parse("2017-01-05T12:12:12");//默认解析date和time之间必须有字符T //simpledateformat没有严格的大小写区分 Date parse4 = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss").parse("2012-01-05 06:12:12"); System.out.println(parse4);