zoukankan      html  css  js  c++  java
  • time_t和SYSTEMTIME 与TDateTime的转换 (转)

     在vc中实现time_t和SYSTEMTIME 与delphi中的TDateTime的转换。

    delphi中的TDateTime其实就是一个double型。

    TDateTime TimetToDateTime(time_t t)
    {
     double result=(double)t / 86400.0 + 25569;
     return TDateTime(result);
    }

    time_t DateTimeToTimet(TDateTime dt)
    {
     return time_t((dt-25569) * 86400.0);
    }

    void DateTimeToSystemTime(TDateTime dt, LPSYSTEMTIME pst)
    {
     double t= (dt-25569) * 86400.0;
     FILETIME ft;

     LONGLONG ll = LONGLONG((t* 10000000) + 116444736000000000);
     ft.dwLowDateTime = (DWORD) ll;
     ft.dwHighDateTime = (DWORD)(ll >> 32);

     FileTimeToSystemTime( &ft, pst );
    }

    TDateTime SystemTimeToDateTime(SYSTEMTIME st)
    {
     FILETIME ft;
     SystemTimeToFileTime( &st, &ft );

     LONGLONG ll;

     ULARGE_INTEGER ui;
     ui.LowPart = ft.dwLowDateTime;
     ui.HighPart = ft.dwHighDateTime;

     ll = ft.dwHighDateTime;
     ll = (ll<<32) + ft.dwLowDateTime;

     TDateTime result =25569+(LONGLONG)(ui.QuadPart - 116444736000000000) / 864000000000.0;
     return result;
    }

    原文: 

    http://blog.csdn.net/constantine/archive/2008/12/25/3607513.aspx

  • 相关阅读:
    [HDU3094]A tree game
    专题总结(博弈论)
    [ZJOI2009]染色游戏
    [AtCoder3954]Painting Machines
    异或
    种树
    [PA2014]Fiolki
    简单题
    2、JUC--CAS算法
    1、JUC--volatile 关键字-内存可见性
  • 原文地址:https://www.cnblogs.com/doorsky/p/2074178.html
Copyright © 2011-2022 走看看