I have a trace file that each transaction time represented in Windows filetime format. These time numbers are something like this:
- 128166372003061629
- 128166372016382155
- 128166372026382245
Would you please let me know if there are any C/C++ library in Unix/Linux to extract actual time (specially second) from these numbers ? May I write my own extraction function ?
If somebody need convert it in MySQL
FILETIME type is is the number 100 ns increments since January 1 1601.
To convert this into a unix time_t you can use the following.
you may then use the ctime functions to manipulate it.
Assuming you are asking about the FILETIME Structure, then FileTimeToSystemTime does what you want, you can get the seconds from the SYSTEMTIME structure it produces.
Also here's a pure C#ian way to do it.
Here's the result of both methods in my immediate window:
New answer for old question.
Using C++11's
<chrono>
plus this free, open-source library:https://github.com/HowardHinnant/date
One can very easily convert these timestamps to
std::chrono::system_clock::time_point
, and also convert these timestamps to human-readable format in the Gregorian calendar:For me this outputs:
On Windows, you can actually skip the
floor
, and get that last decimal digit of precision:With optimizations on, the sub-expression
(sys_days{1970_y/jan/1} - sys_days{1601_y/jan/1})
will translate at compile time todays{134774}
which will further compile-time-convert to whatever units the full-expression requires (seconds, 100-nanoseconds, whatever). Bottom line: This is both very readable and very efficient.it's quite simple: the windows epoch starts 1601-01-01T00:00:00Z. It's 11644473600 seconds before the UNIX/Linux epoch (1970-01-01T00:00:00Z). The Windows ticks are in 100 nanoseconds. Thus, a function to get seconds from the UNIX epoch will be as follows: