Pyxel
Pyxel

Reputation: 117

Convert Windows time into readable format using r?

I have Windows tick time in milliseconds like 13228488488553 (which should be 12/03/2020 13:08:08 at 1 or 2s approximately). As Windows clock the origin is 1/1/1601. I would like to see it in a readable date/hour format using everything (i.e. not rounding up to seconds, but up to milliseconds). A perfect example format would be DD/MM/YY HH:MM:SS.MSS

I did not find any package doing it, and I tried manually but I am stuck with roundings and leap years. Does anyone know a package or did already do it with a handmade function?

Upvotes: 1

Views: 252

Answers (1)

Ian Campbell
Ian Campbell

Reputation: 24888

Here's an approach with as.POSIXct from base R:

format(as.POSIXct(ticktime/1000,
                  origin = "1601-01-01", tz = "UTC"),
       format = "%d/%m/%Y %H:%M:%OS3")
#[1] "12/03/2020 12:08:08.552"

Edit: Perhaps this is your timezone:

format(as.POSIXct(ticktime/1000,
                  origin = "1601-01-01", tz = "CET"),
       format = "%d/%m/%Y %H:%M:%OS3")
#[1] "12/03/2020 13:08:08.552"

Upvotes: 3

Related Questions