Creating Instances of the ZoneOffset Class - Java Date Time

Java examples for Date Time:Time Zone

Description

Creating Instances of the ZoneOffset Class

Demo Code

import java.time.ZoneOffset;

public class Main {
  public static void main(String[] args) {
    // Create zone-offset using hour, minute, and second
    ZoneOffset zos1 = ZoneOffset.ofHours(-6);
    ZoneOffset zos2 = ZoneOffset.ofHoursMinutes(5, 30);
    ZoneOffset zos3 = ZoneOffset.ofHoursMinutesSeconds(8, 30, 45);
    System.out.println(zos1);/*from   ww  w .j  a v  a 2  s.  co m*/
    System.out.println(zos2);
    System.out.println(zos3);

    // Create zone-offset using offset ID as a string
    ZoneOffset zos4 = ZoneOffset.of("+05:00");
    ZoneOffset zos5 = ZoneOffset.of("Z"); // Same as ZoneOffset.UTC
    System.out.println(zos4);
    System.out.println(zos5);

    // Print the values for zone offset constants
    System.out.println("ZoneOffset.UTC: "  + ZoneOffset.UTC);
    System.out.println("ZoneOffset.MIN: "  + ZoneOffset.MIN);
    System.out.println("ZoneOffset.MAX: "  + ZoneOffset.MAX);  
  }
}

Result


Related Tutorials