Unix Timestamp in R

R stores dates as numeric values internally. Use Sys.time() to get the current timestamp and as.numeric() to convert to a Unix epoch in seconds. The lubridate package (tidyverse) simplifies date arithmetic significantly.

Code Examples

Current timestamp (seconds)

as.numeric(Sys.time())

Sys.time() returns a POSIXct object. Wrapping it in as.numeric() extracts the Unix timestamp in seconds (double-precision, so fractional seconds are preserved).

Current timestamp (milliseconds)

as.numeric(Sys.time()) * 1000

Multiply by 1000 and use floor() or as.integer() if you need an integer millisecond value. R's POSIXct stores time as fractional seconds internally.

Convert timestamp to POSIXct

as.POSIXct(1708560000, origin = "1970-01-01", tz = "UTC")

Reconstruct a POSIXct date-time from a Unix timestamp. Always specify tz = "UTC" to avoid implicit local-timezone conversion.

Format timestamp as string

format(as.POSIXct(1708560000, origin="1970-01-01", tz="UTC"), "%Y-%m-%d %H:%M:%S")

format() applies strftime-style format strings to POSIXct objects. Combine with as.POSIXct to go from Unix timestamp to human-readable string.

Using lubridate (tidyverse)

library(lubridate)
ts <- as_datetime(1708560000)
class(ts) # POSIXct

lubridate's as_datetime() assumes UTC and is more readable than base R. It returns a POSIXct object compatible with ggplot2 and dplyr workflows.

Note

R's POSIXct class stores time as seconds since 1970-01-01 UTC — the same as Unix epoch. The key gotcha is that R's as.POSIXct() uses the local timezone by default if you don't specify tz = "UTC". Always be explicit to avoid off-by-hours bugs in data analysis.

Main Epoch Converter

Use the homepage when you need epoch to date, date to epoch, or a full epoch converter

This R guide shows how to create and parse Unix timestamps in code. If your next step is broader search intent like epoch converter, epoch to date, epoch time to date, or unix epoch converter, jump back to the live homepage tools to paste a raw Unix value, auto-detect seconds versus milliseconds, and copy the readable answer instantly.

Related Tools

More free tools for developers debugging timestamps, schedules, and text changes.