java.time.ZoneId.ofOffset() Method Example



Description

The java.time.ZoneId.ofOffset(String prefix, ZoneOffset offset) method obtains an instance of ZoneId wrapping an offset.

Declaration

Following is the declaration for java.time.ZoneId.ofOffset(String prefix, ZoneOffset offset) method.

public static ZoneId ofOffset(String prefix, ZoneOffset offset)

Parameters

  • prefix − the time-zone ID, not null.

  • offset − the offset, not null.

Return Value

the zone ID, not null

Exceptions

IllegalArgumentException − if the prefix is not one of "GMT", "UTC", or "UT", or "".

Example

The following example shows the usage of java.time.ZoneId.ofOffset(String prefix, ZoneOffset offset) method.

package com.tutorialspoint;

import java.time.ZoneId;
import java.time.ZoneOffset;

public class ZoneIdDemo {
   public static void main(String[] args) {
 
      System.out.println(ZoneId.ofOffset("UTC",ZoneOffset.UTC));  
   }
}

Let us compile and run the above program, this will produce the following result −

UTC
Advertisements