LocalDateTime
包含日期和时间。默认格式是 yyyy-MM-dd-HH-mm-ss.zzz. 要创建它的实例,需要传入 LocalDate
和LocalTime
:
LocalDateTime today = LocalDateTime.now(); System.out.println("现在时间"+today); today = LocalDateTime.of(LocalDate.now(), LocalTime.now()); System.out.println("现在时间2"+today); LocalDateTime specificDate = LocalDateTime.of(2014, Month.JANUARY, 1, 10, 10, 30); System.out.println("特定时间"+specificDate); LocalDateTime today1 = LocalDateTime.now(ZoneId.of("UTC-1")); System.out.println("东一区时间"+today1); //Getting date from the base date i.e 01/01/1970 LocalDateTime dateFromBase = LocalDateTime.ofEpochSecond(10000, 0, ZoneOffset.UTC); System.out.println("1970年一万秒后 "+dateFromBase);