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 manually convert an IP address to binary

For IP Address: 182.167.10.48 the complete binary value is: 10110110.10100111.00001010.00110000 Each decimal number in an IP address is represented at a binary octet (8 binary digits). Using the table below for each decimal in the IP... Continue →