as known, Windows stores time stamps in FILETIME format, a
8-Byte-Value. FILETIME format is the number of ticks, in 100ns
increments, since 00:00 1 Jan, 1601 (UTC). Since the rest of the world
uses the Unix definition of time, which is the number of seconds since
00:00 1 Jan 1970, we must be able to translate the FILETIME format to
the Unix time format. I heard, this is done with the following
equation:
(Unix Time) = A * (NT Time) + B
Since the ticks in FILETIME are at 100 nanoseconds intervals, we know
that "A" is 10^-7. The trick is finding "B". "B" is the number of
seconds between 1 Jan 1601 and 1 Jan 1970. This is documented with
MSDN and open source initiatives that "B" is 11644473600.
But if I calculate
Unix Time = 0,0000001 * 40B3B13FED2AC001 + 11644473600
I don't get a valid Unix Time. So what's wrong? Who can help me?
Thanx
Martin Besser
Hope this helps.
--
QuickHare
(QuickHare "at" Hotmail "dot" com)
Well, you don't want to *add* 11644473600 -- you want to subtract it!
I tried it and it works fine...
Dim A As Double, B As Double
A = 10 ^ -7
B = 11644473600#
Dim NTTime As Double
NTTime = UnsignLong(FT.dwLowDateTime) + UnsignLong(FT.dwHighDateTime) * 2 ^
32#
Dim UnixTime As Long
UnixTime = A * NTTime - B
BTW, UnsignLong() takes a long, and returns it as a Double as if it were an
unsigned value, which is very important here.
Of course, using one of my libraries (available from my site), it's much
eaiser to just do...
UnixTime = DateToEpoch(FileTimeToDate(FT))
Murphy
www.ConstantThought.com
> The trick is finding "B". "B" is the number of seconds
> between 1 Jan 1601 and 1 Jan 1970. This is documented with
> MSDN and open source initiatives that "B" is 11644473600.
There's no trick, really. VB will tell you what it is:
Dim B As Currency
B = DateDiff("s", "1 Jan 1601", "1 Jan 1970")
Your other constant (0.0000001) is also correct. But you do have a problem with the sample FileTime you have used. Firstly, you haven't preceeded it with &H (to show that it is a hex string) but apart from that you are using a value that is simply not realistic (far too large). You have used the hex value:
40B3B13FED2AC001
whereas a file that is created today (8th March 2004) will have a FileTime of something like:
01C404A04C9F4000
So it would appear that you have a problem with the part of your code that is reading the FileTime (which you haven't posted).
Mike