Re: [R] Time conversion from Win32 64bit FILETIME?

From: Alberto Monteiro <albmont_at_centroin.com.br>
Date: Thu 19 Oct 2006 - 18:38:48 GMT

Jim Holtman wrote:
>
> One way might be to convert the number to POSIXct by scaling it based
> that POSIXct is from 1970 and your number is from 1601. So if you
> subtract the difference between 1601 and 1970 then you should have a
> compliant number for R:
>
> # read your number
> x <- 12345678901234567890 # big number (your 64-bit time)
> x.sec <- x / 10^9 # convert to seconds
>
No, it's not the number of ms, it's the number of 100ns, so the way to convert is

x.sec <- x / 10000000 # 10 million - I hope I didn't place an extra 0 # BTW: is there a number format with thousand separators? x.sec <- x / 10e7 # better to write this way :-)

> xBase <- unclass(as.POSIXct('1601-1-1')) # your time base, relative
> to 1970
> x.sec <- x.sec - abs(xBase) # scale to 1970
> x.time <- structure(x.sec, class=c("POSIXt", "POSIXct")) # convert
> to POSIXct
>
I would do it in a simpler way:

  win.xp.filetime <- (400 * 365 + 100 - 3) * 10e7 # 2001-01-01   x <- as.Date("1601-01-01") + win.xp.filetime / 10e7   x

[1] "2001-01-01"

This supposes, of course, that Windows is compliant with the Gregorian Calendar [until a few years ago, Excel did consider 1900 a leap year, so care must be taken here].

Alberto Monteiro



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Oct 20 11:15:09 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 20 Oct 2006 - 01:30:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.