How to convert a Unix timestamp to POSIXct in R (i.e. 1532289300 = 2018-07-22 19:55:00)

If you are converting a column of Unix timestamps in a dataframe:

> df$Your.Times <- as.POSIXct(df$Your.Times, origin = “1970-1-1”)
[1] [POSIXct datetimes]

… or …

If you are converting a single Unix timestamp:

> yourtime = as.POSIXct(1532289300, origin = “1970-1-1”)
[1] 2018-07-22 19:55:00

Note: These solutions require the lubridate package.

Explanation:

In brief, as understood by Unix, time started on January 1, 1970 (the epoch date). The epoch date is represented as “0” Coordinated Universal Time (“UTC”) in Unix systems and all datetimes after the epoch date are represented as the number of seconds that have passed since the epoch date. Therefore, a Unix timestamp is the number of seconds since January 1, 1970 … approximately … leap seconds are not counted. as.POSIXct works be converting the number of seconds since January 1, 1970 into a readable datetime.

 
1
Kudos
 
1
Kudos

Now read this

How to display and flush the DNS Resolver Cache on Windows

The DNS Resolver Cache is a temporary storage cache for DNS lookups on your local machine that allows for efficient resolution of recently accessed URLs to IP addresses. To display the DNS Resolver Cache in Windows enter the following... Continue →