ZoneId ofOffset() method in Java with Examples
The ofOffset() method of the ZoneId class used to obtain an instance of ZoneId wrapping an offset.If the prefix passed in this method is “GMT”, “UTC”, or “UT” a ZoneId with the prefix then the non-zero offset is returned and If the prefix is empty “” then the ZoneOffset is returned.
Syntax:
ublic static ZoneId ofOffset(String prefix,
ZoneOffset offset)
Parameters: This method accepts two parameters prefix and offset where prefix represents the time-zone ID and offset represents the offset.
Return value: This method returns the zoneId.
Exception: This method throws an IllegalArgumentException if the prefix is not one of “GMT”, “UTC”, or “UT”, or “”.
Below programs illustrate the ofOffset() method:
Program 1:
// Java program to demonstrate // ZoneId.ofOffset() method import java.time.*; public class GFG { public static void main(String[] args) { // create ZoneId object ZoneId zoneId = ZoneId.ofOffset("UTC", ZoneOffset.UTC); // print result System.out.println("ZoneId:" + zoneId); } } |
ZoneId:UTC
Program 2:
// Java program to demonstrate // ZoneId.ofOffset() method import java.time.*; public class GFG { public static void main(String[] args) { // create ZoneId object ZoneId zoneId = ZoneId.ofOffset("GMT", ZoneOffset.MAX); // print result System.out.println("ZoneId:" + zoneId); } } |
ZoneId:GMT+18:00
Recommended Posts:
- ZoneOffset ofOffset() method in Java with Examples
- ZoneId from() method in Java with Examples
- ZoneId getDisplayName() method in Java with Examples
- ZoneId getRules() method in Java with Examples
- ZoneId getId() method in Java with Examples
- ZoneId getAvailableZoneIds() method in Java with Examples
- ZoneId hashCode() method in Java with Examples
- ZoneId equals() method in Java with Examples
- ZoneId systemDefault() method in Java with Examples
- ZoneId toString() method in Java with Examples
- ZoneId normalized() method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java lang.Long.builtcount() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai



