Dates and Time Series
UTC Time Shift
Fixed Instants
POSIXct stores date-time instants. Using an explicit UTC time zone keeps examples deterministic across machines.
Program
Play the script to shift a fixed UTC instant by selected hours.
utc_time_shift.R
base_time <- as.POSIXct("2026-01-01 08:00:00", tz = "UTC")
hour_shift <-
event_time <- base_time + hour_shift * 3600
stamp <- format(event_time, "%Y-%m-%d %H:%M", tz = "UTC")
label <- paste("UTC", stamp)
cat(label, "\n", sep = "")
base_time <- as.POSIXct("2026-01-01 08:00:00", tz = "UTC")
hour_shift <-
event_time <- base_time + hour_shift * 3600
stamp <- format(event_time, "%Y-%m-%d %H:%M", tz = "UTC")
label <- paste("UTC", stamp)
cat(label, "\n", sep = "")
base_time <- as.POSIXct("2026-01-01 08:00:00", tz = "UTC")
hour_shift <-
event_time <- base_time + hour_shift * 3600
stamp <- format(event_time, "%Y-%m-%d %H:%M", tz = "UTC")
label <- paste("UTC", stamp)
cat(label, "\n", sep = "")
POSIXct
`as.POSIXct(..., tz = "UTC")` creates a date-time instant with an explicit zone.
seconds
`hour_shift * 3600` converts hours into seconds for time arithmetic.
UTC
Formatting with `tz = "UTC"` avoids host-local time-zone differences.