提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
在日期时间中添加期间和持续时间的差异
/* from N o w J a v a . c o m */ import java.time.Duration; import java.time.LocalDateTime; import java.time.Month; import java.time.Period; import java.time.ZoneId; import java.time.ZonedDateTime; public class Main { public static void main(String[] args) { ZoneId usCentral = ZoneId.of("America/Chicago"); LocalDateTime ldt = LocalDateTime.of(2019, Month.MARCH, 10, 7, 30); ZonedDateTime zdt1 = ZonedDateTime.of(ldt, usCentral); Period p1 = Period.ofDays(1); Duration d1 = Duration.ofHours(24); /*来自 nowjava - 时 代 Java*/ // Add a period of 1 day and a duration of 24 hours ZonedDateTime zdt2 = zdt1.plus(p1); ZonedDateTime zdt3 = zdt1.plus(d1); System.out.println(