//获取当前日期,默认当前时区的
LocalDateTime localDateTime = LocalDateTime.now();
System.out.println(localDateTime);
//按照固定格式转成String
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String dateTime = localDateTime.format(format);
System.out.println(dateTime);
//获取年、月、日、小时、分、秒都变成轻松、好记多了
String dateGet = "Year : " + localDateTime.getYear() + ",month: " + localDateTime.getMonthValue() +
",Day: " + localDateTime.getDayOfMonth() + " hour: " + localDateTime.getHour() +
",minute: " + localDateTime.getMinute() + ",second: " + localDateTime.getSecond();
System.out.println(dateGet);
//直接转LocalDate,没有时、分、秒
LocalDate localDate1 = localDateTime.toLocalDate();
System.out.println(localDate1);
//LocalDate转String
String dateformat = localDate1.format(DateTimeFormatter.ofPattern("yyyy/MM/dd"));
System.out.println(dateformat);
//LocalDateTime转成ZonedDateTime
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime zoneDateTime = localDateTime.atZone(zoneId);
//再转成 java.util.Date()
Date ndate = Date.from(zoneDateTime.toInstant());
System.out.println("change to date:");
System.out.println(ndate);
//直接获取当前LocalDate
LocalDate localDate = LocalDate.now();
System.out.println(localDate);
//直接获取当前
ZonedDateTime.now();
Date nowDate = new Date();
System.out.println(nowDate);