Unix Timestamp in R

Use base R `as.POSIXct` and `Sys.time`. The `lubridate` package provides nicer parsing helpers.

Common Operations

Get current Unix timestamp

ts <- as.numeric(Sys.time())
# 1706745600

Convert Unix timestamp to date (UTC)

dt <- as.POSIXct(1706745600, origin = '1970-01-01', tz = 'UTC')
# '2024-01-31 22:40:00 UTC'

Convert date to Unix timestamp

ts <- as.numeric(as.POSIXct('2024-01-31 22:40:00', tz = 'UTC'))

Format as ISO 8601

format(Sys.time(), '%Y-%m-%dT%H:%M:%SZ', tz = 'UTC')

Other Languages

Need the full converter? Open the Timestamp Converter →