For Developers

Unix Timestamp in R

How to get the current timestamp, convert it to a date, and convert a date back to a timestamp in R — plus the origin argument that R silently gets wrong if you skip it.

as.numeric(Sys.time())
ts <- 1750000000
as.POSIXct(ts, origin = "1970-01-01", tz = "UTC")
d <- as.POSIXct("2025-06-15 12:00:00", tz = "UTC")
as.numeric(d)

The R-specific pitfall

as.POSIXct() requires an explicit origin argument to convert a raw number into a date, and if you leave it out, R doesn't error — it just refuses silently in some versions or falls back to a default that isn't always 1970-01-01 depending on locale settings and package versions. It's one of the few base-R functions where a required-in-practice argument is technically optional in the signature. Always pass origin = "1970-01-01", tz = "UTC" explicitly, every time, rather than trusting the default for a given environment.

Have a timestamp right now?

Paste it into the Timestamp ⇄ Date Converter to check it instantly, in any timezone, without writing any code. Working across several languages on the same project? The full Epoch Time in Programming Languages guide has all of them side by side for quick comparison.

Related

Related tools & reading