[R] Time conversion from Win32 64bit FILETIME?
Alberto Monteiro
albmont at centroin.com.br
Thu Oct 19 20:38:48 CEST 2006
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
More information about the R-help
mailing list