LocalDateTime now = LocalDateTime.now();
//获取当前日期
System.out.println("now = " + now);//now = 2020-01-27T22:23:33.320
System.out.println("now.getYear() = " + now.getYear());//now.getYear() = 2019
//注意获取月份的两个方法的区别
System.out.println("now.getMonth() = " + now.getMonth());//now.getMonth() = JANUARY
System.out.println("now.getMonthValue() = " + now.getMonthValue());//now.getMonthValue() = 1
System.out.println("now.getDayOfMonth() = " + now.getDayOfMonth());//now.getDayOfMonth() = 27
System.out.println("now.getHour() = " + now.getHour());
System.out.println("now.getMinute() = " + now.getMinute());
System.out.println("now.getSecond() = " + now.getSecond());
//构造指定日期,eg.2020-08-08
LocalDate diyDate = LocalDate.of(2020, 8, 8);
System.out.println("diyDate = " + diyDate);
//构造指定时间,eg.2020-08-08 00:00:00
LocalDateTime diyTime = LocalDateTime.of(2020, 8, 8, 0, 0, 0);
System.out.println("diyTime = " + diyTime);//diyDate = 2020-08-08T00:00
//修改日期
//①增加/减少几个月
LocalDateTime localDateTime = LocalDateTime.now();
System.out.println("localDateTime = " + localDateTime);//localDateTime = 2020-01-27T22:37:05.546
//下个月,plusMonth()
localDateTime = localDateTime.plusMonths(1);
System.out.println("localDateTime = " + localDateTime);//localDateTime = 2020-02-27T22:37:05.546
//上个月,-1
localDateTime = localDateTime.minusMonths(1);
//或者使用 plusMonth(-1)
//localDateTime = localDateTime.plusMonths(-1);
System.out.println("localDateTime = " + localDateTime);//localDateTime = 2020-01-27T22:37:05.546
//②修改到指定日期
localDateTime = localDateTime.withYear(2200);
System.out.println("localDateTime = " + localDateTime);//localDateTime = 2200-01-27T22:43:26.722
//格式化日期
//①自定义日期格式
String diyFormatDate = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
System.out.println("diyFormatDate = " + diyFormatDate);//formatDate = 2020-01-27 22:47:21
//②几种基本格式
String format = now.format(DateTimeFormatter.ISO_DATE);
System.out.println("format = " + format);//format = 2020-01-27
format = now.format(DateTimeFormatter.BASIC_ISO_DATE);
System.out.println("format = " + format);//format = 20200127
//解析日期
LocalDateTime parse = LocalDateTime.parse("2020-01-27 22:47:21", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
System.out.println("parse = " + parse);//parse = 2020-01-27T22:47:21