Java Date Time - ZoneOffset of(String offsetId) example








ZoneOffset of(String offsetId) creates an instance of ZoneOffset using the ID.

The parsing accepts all the formats generated by getId(), plus some additional formats:

Z - for UTC /* w ww. j  ava  2  s  . c o  m*/
+h 
+hh 
+hh:mm 
-hh:mm 
+hhmm 
-hhmm 
+hh:mm:ss 
-hh:mm:ss 
+hhmmss 
-hhmmss

The maximum supported range is from +18:00 to -18:00 inclusive.





Syntax

of has the following syntax.

public static ZoneOffset of(String offsetId)

Example

The following example shows how to use of.

import java.time.ZoneOffset;
//w  w w . j a  v a 2 s  .  c  o  m
//ZoneOffset is the period of time representing 
//a difference between Greenwich/UTC and a time zone.

public class Main {
  public static void main(String[] args) {
    ZoneOffset offset = ZoneOffset.of("+2:00");
    System.out.println(offset);
  }
}