- java.time Package Classes
- java.time - Home
- java.time - Clock
- java.time - Duration
- java.time - Instant
- java.time - LocalDate
- java.time - LocalDateTime
- java.time - LocalTime
- java.time - MonthDay
- java.time - OffsetDateTime
- java.time - OffsetTime
- java.time - Period
- java.time - Year
- java.time - YearMonth
- java.time - ZonedDateTime
- java.time - ZoneId
- java.time - ZoneOffset
- java.time Package Enums
- java.time - Month
- java.time Useful Resources
- java.time - Discussion
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