提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用本地日期、时间和日期时间
import java.time.LocalDate; import java.time.LocalDateTime;/*来自 N o w J a v a . c o m*/ import java.time.LocalTime; import java.time.Month; public class Main { public static void main(String[] args) { // Create a local date and time LocalDate ld = LocalDate.of(2019, Month.MAY, 11); LocalTime lt = LocalTime.of(8, 52, 23); System.out.println("ld: " + ld); System.out.println("ld.isLeapYear(): " + ld.isLeapYear()); System.out.println("lt: " + lt); // Create a local datetime from the local date and time LocalDateTime ldt = LocalDateTime.of(ld, lt); System.out.println("ldt: " + ldt); // Add 2 months and 25 minutes to the local datetime LocalDateTime ldt2 = ldt.plusMonths(2).plusMinutes(25) ; System.out.println("ldt2: " + ldt2); /**来自 n o w j a v a . c o m**/