13 digit UNIX Epoch to date time

Hi all, here a link to a project I'm currently struggling with Posit Cloud

I am trying to convert the UNIX epoch to a standard date time, but when I attempt the various syntax I get the following 43074-03-14 UTC

any tips?

library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union
e <- 1685438026
as_datetime(e)
#> [1] "2023-05-30 09:13:46 UTC"

Created on 2023-05-30 with reprex v2.0.2

Maybe your epoch 13 digit number includes milliseconds? Try stripping those off prior to conversion.
Your Posit cloud project is not publicly available. To get more help you’ll need to post some examples.

Thanks! This works, but doesn't give me the time when I strip off the milliseconds.

When I use the following it almost works, but doesn't account for daylight savings time. So rather that 8pm as the UNIX timestamp convertor shows it's 7pm.

as.POSIXct(1306281600000/1000, origin= "1970-01-01", tz ="EST")

Try a time zone location rather than setting EST.

as.POSIXct(1306281600000/1000, origin= "1970-01-01", tz ="America/New_York")
[1] "2011-05-24 20:00:00 EDT"

Thank you! I didn't have the _ between New and York.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.