CKTIS / Java
ZoneOffset — a fixed offset from UTC
ZoneOffset describes a fixed offset from UTC, not regional time-zone rules. ZoneOffset.UTC represents the zero offset, whose identifier is Z.
Version: Java SE 21; repository runtime, production runtime not attested
Syntax
ZoneOffset.UTC
ZoneOffset.of("+02:00")
ZoneOffset.ofHoursMinutes(-5, -30)
offset.getId()
offset.getTotalSeconds()java.time.ZoneOffset represents a fixed difference from UTC, such as +02:00. It stores neither a date nor a time. A regional ZoneId, such as Europe/Paris, defines rules for finding the offset at an instant; an offset alone does not describe daylight-saving changes.
ZoneOffset.UTC represents the zero offset; its getId() returns Z. Factories such as of("+02:00") and ofHoursMinutes(-5, -30) create other values. Nonzero components must have matching signs. The range is -18:00 through +18:00 inclusive; an invalid value causes DateTimeException.
Instances are immutable and thread-safe. Compare them with equals, not ==, and do not use them as synchronization locks. The example shows normalized identifiers, an offset in seconds, and equality between two representations of the zero offset.
Examples
import java.time.ZoneOffset;
public class Main {
public static void main(String[] args) {
ZoneOffset offset = ZoneOffset.ofHoursMinutes(-5, -30);
System.out.println(ZoneOffset.UTC.getId());
System.out.println(offset.getId());
System.out.println(offset.getTotalSeconds());
System.out.println(ZoneOffset.UTC.equals(ZoneOffset.of("+00:00")));
}
}Result
Z -05:30 -19800 true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.