Java ZoneOffset get from ZonedDateTime

Description

Java ZoneOffset get from ZonedDateTime

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

public class Main {
  public static void main(String[] args) {
    LocalDateTime dt = LocalDateTime.now();

    ZoneId zone = ZoneId.of("+06:00");
    ZonedDateTime zdt = dt.atZone(zone);
    ZoneOffset offset = zdt.getOffset();
    String out = String.format("%35s %10s%n", zone, offset);

    System.out.println(out);/*from   w w w .  j  a v a  2  s  .c  om*/
  }
}



PreviousNext

Related