ZoneId.of constructor

ZoneId.of(
  1. String zoneId
)

Factory constructor to create a ZoneId from a string-based zone ID.

Validates that the input string is non-empty. Throws an InvalidArgumentException if an empty string is passed.

Example:

ZoneId ny = ZoneId.of('America/New_York');

zoneId must be a valid time zone name, such as 'UTC' or 'Asia/Tokyo'. This class does not validate against all IANA time zones, but you can use ZoneId.getAvailableZoneIds for commonly supported names. Represents a time zone identifier, abstracting the concept of region-based or offset-based zone IDs (e.g., 'UTC', 'America/New_York').

The ZoneId class allows specifying or retrieving time zone information in a controlled and type-safe manner.

Example:

ZoneId utc = ZoneId.of('UTC');
print(utc.id); // Output: UTC

ZoneId systemZone = ZoneId.systemDefault();
print(systemZone); // Output: e.g., "PDT", "CET", depending on system

Implementation

factory ZoneId.of(String zoneId) {
  if (zoneId.isEmpty) {
    throw InvalidArgumentException('Zone ID cannot be empty');
  }
  return ZoneId._(zoneId);
}