Vint
Vint

Reputation: 499

Convert 14 digit datetime object to POSIXct

I have an array of datetime objects created in python, that I'd like to read into R as a POSIXct. For example, the 14 digit datetime object looks like:

736908.51782407

I believe this is the datetime

2018, 8, 2, 12, 25, 55

But I'm not sure how to convert the numerical datetime to POSIXct in R

Upvotes: 0

Views: 71

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521339

Your 14 digit time value appears to the number of days since 0001-01-01. If so, we can convert it to seconds since 0001-01-01 and then use as.POSIXct():

val <- 736908.51782407
val <- val * 24 * 60 * 60
as.POSIXct(val, origin="0001-01-01")

[1] "2017-08-03 14:25:39 CEST"

Demo

The output does not line up exactly with what you are expecting. I don't Python well enough to comment. There could also be timezone issues with as.POSXIct, but this answer seems to be on the right track.

Upvotes: 4

Related Questions