Java ZonedDateTime create from LocalDateTime and ZoneId

Description

Java ZonedDateTime create from LocalDateTime and ZoneId

import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;

public class Main {
  public static void main(String[] args) {
    ZoneId usChicago = ZoneId.of("America/Chicago");
    ZoneOffset offset5 = ZoneOffset.of("-05:00");
    ZoneOffset offset6 = ZoneOffset.of("-06:00");
    ZoneOffset offset7 = ZoneOffset.of("-07:00");

    LocalDateTime ldt = LocalDateTime.of(2013, Month.NOVEMBER, 3, 1, 30);
    ZonedDateTime zdt5 = ZonedDateTime.ofLocal(ldt, usChicago, offset5);
    ZonedDateTime zdt6 = ZonedDateTime.ofLocal(ldt, usChicago, offset6);
    ZonedDateTime zdt7 = ZonedDateTime.ofLocal(ldt, usChicago, offset7);
    System.out.println("With offset " + offset5 + ": " + zdt5);
    System.out.println("With offset " + offset6 + ": " + zdt6);
    System.out.println("With offset " + offset7 + ": " + zdt7);
  }/*www  . j a  v  a  2  s  .c o  m*/
}



PreviousNext

Related