public class DateAPI {
static final String SEP = "#################################################################";

public static void main(String[] args) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss:SSS");
// 获取当前的日期时间
LocalDateTime currentTime = LocalDateTime.now();
currentTimeOpt(currentTime);
System.out.println(SEP);

transDateTime(currentTime);
System.out.println(SEP);

zoneDateTime();
System.out.println(SEP);

System.out.println("format date: " + LocalDateTime.now().format(formatter));
}

public static void dateStr2Date() {
// 获得当前时间
LocalDateTime ldt = LocalDateTime.now();
System.out.println(ldt);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
String format = ldt.format(dtf);
System.out.println(format);

String str1="2019-11-13 11:11:29";
DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime parse = LocalDateTime.parse(str1, dtf1);
System.out.println(parse);
}

/**
* currentTime operate
* */
public static void currentTimeOpt(LocalDateTime currentTime) {
System.out.println("current time is: " + currentTime);

System.out.println("current date: " + currentTime.toLocalDate());
System.out.println("current time: " + currentTime.toLocalTime());

System.out.println("current year: " + currentTime.getYear());
System.out.println("current month: " + currentTime.getMonth());
System.out.println("current month value: " + currentTime.getMonthValue());
System.out.println("current day: " + currentTime.getDayOfMonth());

System.out.println("current hour: " + currentTime.getHour());
System.out.println("current minute: " + currentTime.getMinute());
System.out.println("current second: " + currentTime.getSecond());

System.out.println("current day of year: " + currentTime.getDayOfYear());
System.out.println("current day of week: " + currentTime.getDayOfWeek());
}

public static void transDateTime(LocalDateTime currentTime) {
LocalDateTime localDateTime = currentTime.withDayOfMonth(10).withYear(2012);
System.out.println(currentTime + " -> " + localDateTime);

LocalDate localDate = LocalDate.of(2018, Month.DECEMBER, 12);
System.out.println(localDate);
// 加12个月
System.out.println(localDate.plusMonths(12));
// 减1个月
System.out.println(localDate.plusMonths(-1));
localDate = LocalDate.of(2018, 12, 12);
System.out.println(localDate);
localDate = LocalDate.parse("2018-01-01");
System.out.println(localDate);

LocalTime localTime = LocalTime.of(18, 30, 01);
System.out.println(localTime);

localTime = LocalTime.parse("20:13:14");
System.out.println(localTime);
}

public static void zoneDateTime() {
// 获取当前时间日期
ZonedDateTime zonedDateTime = ZonedDateTime.parse("2015-12-03T10:15:30+05:30[Asia/Shanghai]");
System.out.println("zonedDateTime: " + zonedDateTime);

ZoneId zoneId = ZoneId.of("Europe/Paris");
System.out.println("ZoneId: " + zoneId);

ZoneId currentZone = ZoneId.systemDefault();
System.out.println("当期时区: " + currentZone);
}

}