Warm tip: This article is reproduced from serverfault.com, please click

Time Converter

发布于 2010-12-09 20:50:47

Is there a tool that converts the time(NULL) value to the WINDOWS time.

The time(NULL) will give time in seconds since Jan 1, 1970. Now if i enter that value to this tool it must give me the time in date and hours, minutes and seconds.

In C++ we use the time(NULL) object a lot to send time.

Questioner
ckv
Viewed
0
wallyk 2010-12-10 08:49:46

If by Windows time you mean the 64-bit time used in NTFS, you can use the conversion:

int64 wintime = 100000000uL * time(NULL) + 0x19db1ded53e8000uLL

where
   int64 is the type used by your compiler for 64-bit integers.

NT time is based on the origin at 1601-01-01 00:00:00 utc and counts ten million units per second—a timing precision of 100 ns. It assumes a simple leap year sequence and ignores the calendar complexities around 1752.

So, by multiplying the Unix time by ten million, and adding 116444736000000000 (decimal) or 0x19DB1DED53E8000, which is the difference between 1970-01-01 and 1601-01-01, one can easily convert from one to the other.