Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Windows Filetime to second in Unix/Linux

Tags:

c++

c

time

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 ?

like image 328
ARH Avatar asked May 28 '11 12:05

ARH


People also ask

How do I convert FileTime to datetime?

get(file); BasicFileAttributes attr = Files. readAttributes(filepath,BasicFileAttributes. class); FileTime date = attr. creationTime(); DateFormat df = new SimpleDateFormat("MM/dd/yyyy"); String dateCreated = df.

What is Windows FileTime?

Remarks. A Windows file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC). Windows uses a file time to record when an application creates, accesses, or writes to a file.


1 Answers

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:

#define WINDOWS_TICK 10000000 #define SEC_TO_UNIX_EPOCH 11644473600LL  unsigned WindowsTickToUnixSeconds(long long windowsTicks) {      return (unsigned)(windowsTicks / WINDOWS_TICK - SEC_TO_UNIX_EPOCH); } 
like image 90
Eugene Avatar answered Oct 12 '22 09:10

Eugene