zoukankan      html  css  js  c++  java
  • Windows FILETIME 与UNIX时间的转换

    windows FILETIME时间从1601/01/01 零时零分零秒开始计时,windows每个时钟滴答将计数加一,每个时钟滴答的间隔是100 nanoseconds(纳秒,1秒=10的九次方纳秒),即每个时钟滴答= 10 (-7)秒。

    unix、linux时间是从1970/01/01零时零分零秒开始计数,每秒计数加1. 197001/01与1601/01/01的时间间隔是11644473600秒。

    所以从windows滴答时间转化为unix时间的代码为:

    #define WINDOWS_TICK 10000000  //10的7次方
    #define SEC_TO_UNIX_EPOCH 11644473600LL //1601与1970的时间间隔
    
    unsigned WindowsTickToUnixSeconds(long long windowsTicks)
    {
         return (unsigned)(windowsTicks / WINDOWS_TICK - SEC_TO_UNIX_EPOCH);
    }
    

     从timeval转化为FILETIME的代码为:

    void FileTimeToTimeval(FILETIME *pFileTime, struct timeval *pTimeval)
    {
        CalcOffsetFrom1601To1970(); //11644473600LL*10^7
        ULONGLONG ul64FileTime = 0;
     
        ul64FileTime |= pFileTime->dwHighDateTime;
        ul64FileTime <<= 32;
        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 * 10;
        x += g_ullOffsetFrom1601To1970;
        pFileTime->dwHighDateTime = (ULONG)(x >> 32);
        pFileTime->dwLowDateTime = (ULONG)x;
    }
    
  • 相关阅读:
    js点击重置按钮重置表单
    Flash文件在asp页面无法播放,网页上面的Flash文件在火狐浏览器不播放
    更新域名解析以后,IP在cmd中ping不正确,清理DNS缓存
    简单PHP会话(session)说明
    delphi 事件和属性的绑定
    读书笔记(乡土中国)
    读书笔记(支付战争)
    读书笔记(从0到1)
    读书笔记(创业维艰)
    读书笔记(三体)
  • 原文地址:https://www.cnblogs.com/stephen-init/p/4042257.html
Copyright © 2011-2022 走看看