Conversion of Windows FILETIME to Unix time

Source: Internet
Author: User
Tags filetime

Windows filetime time starts from 1601/01/01 to 0 minutes and 0 seconds, windows each clock tick will count plus one, each clock tick interval is nanoseconds (nanosecond, 1 seconds =10 Nine square nanoseconds), that is, each clock tick = 10 (-7) seconds.

UNIX, Linux time is counting from 1970/01/01 to 0 minutes and 0 seconds, counting plus 1 per second. The time interval between 197001/01 and 1601/01/01 is 11,644,473,600 seconds.

So the code to convert from Windows tick time to Unix time is:

#define Windows_tick 10000000  //10 7-Square # # Sec_to_unix_epoch 11644473600LL//1601 with 1970 time interval unsigned Windowsticktounixseconds (Long long windowsticks) {     return (unsigned) (windowsticks/windows_tick-sec_to_unix_ EPOCH);}

The code converted from Timeval to FILETIME is:

void Filetimetotimeval (FILETIME *pfiletime, struct timeval *ptimeval) {    calcoffsetfrom1601to1970 ();// 11644473600ll*10^7    Ulonglong ul64filetime = 0;     Ul64filetime |= pfiletime->dwhighdatetime;    Ul64filetime <<=;    Ul64filetime |= pfiletime->dwlowdatetime;     Ul64filetime-= g_ulloffsetfrom1601to1970;    Ptimeval->tv_sec = (long) (ul64filetime/10000000);    Ptimeval->tv_usec = (long) ((ul64filetime% 10000000)/10);} void Timevaltofiletime (struct timeval *ptimeval, FILETIME *pfiletime) {    calcoffsetfrom1601to1970 ();    ULONGLONG x = ptimeval->tv_sec * nspersec + ptimeval->tv_usec *;    x + = g_ulloffsetfrom1601to1970;    Pfiletime->dwhighdatetime = (ULONG) (x >> +);    Pfiletime->dwlowdatetime = (ULONG) x;}

Conversion of Windows FILETIME to Unix time

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.