Java ZonedDateTime add Period

Description

Java ZonedDateTime add Period

import java.time.Duration;
import java.time.LocalDateTime;
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.now();
    ZonedDateTime zdt1 = ZonedDateTime.of(ldt, usCentral);
    Period p1 = Period.ofDays(1);
    Duration d1 = Duration.ofHours(24);

    ZonedDateTime zdt2 = zdt1.plus(p1);
    ZonedDateTime zdt3 = zdt1.plus(d1);

    System.out.println(zdt1);/* w  ww  .ja  v a  2 s . c om*/
    System.out.println(zdt2);//added one day
    System.out.println(zdt3);//add 24 hours
  }
}



PreviousNext

Related