TimeZone
id: py-TimeZone
TimeZone
Represents a timezone for use with DateTime, LocalDate, and Time. Timezones handle daylight saving time transitions and regional offsets automatically.
At a Glance
# Common timezones
utc = TimeZone.UTC()
berlin = TimeZone.of('Europe/Berlin')
tokyo = TimeZone.of('Asia/Tokyo')
ny = TimeZone.of('America/New_York')
# System default
local = TimeZone.systemDefault()
# Use with DateTime
now = DateTime.now(berlin)
stream.log_info(f"Berlin: {now.toString()}")
Properties
| Property | Type | Description |
|---|---|---|
id | str | Timezone identifier (e.g., "Europe/Berlin") |
displayName | str | Human-readable name (e.g., "Central European Time") |
tz = TimeZone.of('America/New_York')
stream.log_info(tz.id) # "America/New_York"
stream.log_info(tz.displayName) # "Eastern Time"
Static Properties
UTC()
The UTC timezone.
utc = TimeZone.UTC()
stream.log_info(utc.id) # "UTC"
Methods
of(zoneId)
Returns a TimeZone by its identifier.
| Parameter | Type | Description |
|---|---|---|
zoneId | str | Timezone ID (e.g., "Europe/Berlin", "America/New_York") |
Returns: TimeZone
tz = TimeZone.of('Asia/Tokyo')
Finding Timezone IDs
Use standard IANA timezone IDs. A complete list is available at howtodoinjava.com.
systemDefault()
Returns the system's default timezone.
Returns: TimeZone
local = TimeZone.systemDefault()
stream.log_info(f"Running in: {local.id}")
See Also
DateTime— Use with DateTime.now(zone) and atZone(zone)ZoneOffset— Fixed UTC offset (e.g., +05:30)