LocalDateTime与LocalDate之间转换

2024-10-09 10:55:58 浏览数 (2)

LocalDateTime与LocalDate之间转换

//LocalDateTime转换LocalDate LocalDateTime now2 = LocalDateTime.now(); LocalDate ld2 = now2.toLocalDate(); System.out.println("lt2=" ld2);

//LocalDate转换LocalDateTime LocalDate ld3 = LocalDate.now(); LocalTime lt = LocalTime.of(12,12,0); LocalDateTime ldt = ld3.atTime(lt); System.out.println("ldt=" ldt);

LocalDateTime ldt2 = ld3.atTime(12,20,20); System.out.println("ldt2=" ldt2);

//初始化LocalDateTime LocalDateTime ldt3 = LocalDateTime.of(2023,12,12,12,20,20); System.out.println("ldt3=" ldt3); output: lt2=2023-08-14 ldt=2023-08-14T12:12 ldt2=2023-08-14T12:20:20 ldt3=2023-12-12T12:20:20

0 人点赞