zoukankan      html  css  js  c++  java
  • 【源代码R3】移植一份LARGE_INTEGER转时间的代码

    本代码来自ReactOS-0.4.0lib tl ime.c中的函数RtlTimeToTimeFields(IN PLARGE_INTEGER Time, OUT PTIME_FIELDS TimeFields);

    源代码如下: 

    #define TICKSPERMIN        600000000
    #define TICKSPERSEC        10000000
    #define TICKSPERMSEC       10000
    #define SECSPERDAY         86400
    #define SECSPERHOUR        3600
    #define SECSPERMIN         60
    #define MINSPERHOUR        60
    #define HOURSPERDAY        24
    #define EPOCHWEEKDAY       1
    #define DAYSPERWEEK        7
    #define EPOCHYEAR          1601
    #define DAYSPERNORMALYEAR  365
    #define DAYSPERLEAPYEAR    366
    #define MONSPERYEAR        12
    
    static const unsigned int YearLengths[2] = { DAYSPERNORMALYEAR, DAYSPERLEAPYEAR };
    static const UCHAR MonthLengths[2][MONSPERYEAR] =
    {
        { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
        { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
    };
    
    static __inline int IsLeapYear(int Year)
    {
        return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
    }
    
    static int DaysSinceEpoch(int Year)
    {
        int Days;
        Year--; /* Don't include a leap day from the current year */
        Days = Year * DAYSPERNORMALYEAR + Year / 4 - Year / 100 + Year / 400;
        Days -= (EPOCHYEAR - 1) * DAYSPERNORMALYEAR + (EPOCHYEAR - 1) / 4 - (EPOCHYEAR - 1) / 100 + (EPOCHYEAR - 1) / 400;
        return Days;
    }
    
    VOID RtlTimeToTimeFields(IN PLARGE_INTEGER Time, OUT LPSYSTEMTIME TimeFields)
    {
        const UCHAR *Months;
        ULONG SecondsInDay, CurYear;
        ULONG LeapYear, CurMonth;
        ULONG Days;
        ULONGLONG IntTime = Time->QuadPart;
    
        /* Extract millisecond from time and convert time into seconds */
        TimeFields->wMilliseconds = (WORD) ((IntTime % TICKSPERSEC) / TICKSPERMSEC);
        IntTime = IntTime / TICKSPERSEC;
    
        /* Split the time into days and seconds within the day */
        Days = (ULONG)(IntTime / SECSPERDAY);
        SecondsInDay = IntTime % SECSPERDAY;
    
        /* compute time of day */
        TimeFields->wHour = (WORD) (SecondsInDay / SECSPERHOUR);
        SecondsInDay = SecondsInDay % SECSPERHOUR;
        TimeFields->wMinute = (WORD) (SecondsInDay / SECSPERMIN);
        TimeFields->wSecond = (WORD) (SecondsInDay % SECSPERMIN);
    
        /* compute day of week */
        TimeFields->wDayOfWeek = (WORD) ((EPOCHWEEKDAY + Days) % DAYSPERWEEK);
    
        /* compute year */
        CurYear = EPOCHYEAR;
        CurYear += Days / DAYSPERLEAPYEAR;
        Days -= DaysSinceEpoch(CurYear);
        while (1)
        {
            LeapYear = IsLeapYear(CurYear);
            if (Days < YearLengths[LeapYear])
            {
                break;
            }
            CurYear++;
            Days = Days - YearLengths[LeapYear];
        }
        TimeFields->wYear = (WORD) CurYear;
    
        /* Compute month of year */
        LeapYear = IsLeapYear(CurYear);
        Months = MonthLengths[LeapYear];
        for (CurMonth = 0; Days >= Months[CurMonth]; CurMonth++)
            Days = Days - Months[CurMonth];
        TimeFields->wMonth = (WORD) (CurMonth + 1);
        TimeFields->wDay = (WORD) (Days + 1);
    }
    

      

  • 相关阅读:
    js下拉框二级关联菜单效果代码具体实现
    js实现拉伸拖动iframe的具体代码
    mysql--Ubuntu下设置MySQL字符集为utf8
    python--使用MySQL数据库
    python--笨方法学python 习题52
    python--web.py使用
    python--flask使用
    python--类方法、对象方法、静态方法
    Python--类定义
    堆 在游戏中的运用
  • 原文地址:https://www.cnblogs.com/yvqvan/p/7018877.html
Copyright © 2011-2022 走看看