Java OffsetDateTime create from ZoneId

Description

Java OffsetDateTime create from ZoneId

import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;

public class Main {
  public static void main(String[] args) {
    // Get the instant from the offset date time
    Instant i1 = Instant.now();
    System.out.println("Current Instant: " + i1);

    // Create an offset date time from the instant
    ZoneId usChicago = ZoneId.of("America/Chicago");
    OffsetDateTime odt3 = OffsetDateTime.ofInstant(i1, usChicago);
    System.out.println("Offset datetime from instant: " + odt3);
  }//from ww w.ja  v  a  2  s. c o m
}



PreviousNext

Related