zoned-zone: Get or set the time zone

zoned-zoneR Documentation

Get or set the time zone

Description

  • zoned_time_zone() gets the time zone.

  • zoned_time_set_zone() sets the time zone without changing the underlying instant. This means that the result will represent the equivalent time in the new time zone.

Usage

zoned_time_zone(x)

zoned_time_set_zone(x, zone)

Arguments

x

⁠[zoned_time]⁠

A zoned time to get or set the time zone of.

zone

⁠[character(1)]⁠

A valid time zone to switch to.

Value

  • zoned_time_zone() returns a string containing the time zone.

  • zoned_time_set_zone() returns x with an altered time zone attribute. The underlying instant is not changed.

Examples

x <- year_month_day(2019, 1, 1)
x <- as_zoned_time(as_naive_time(x), "America/New_York")
x

zoned_time_zone(x)

# Equivalent UTC time
zoned_time_set_zone(x, "UTC")

# To force a new time zone with the same printed time,
# convert to a naive time that has no implied time zone,
# then convert back to a zoned time in the new time zone.
nt <- as_naive_time(x)
nt
as_zoned_time(nt, "UTC")

clock documentation built on Sept. 11, 2024, 8:39 p.m.