c++linux64-bit32bit-64bittime-t

64-bit Unix timestamp conversion


Is there any C++ implementation of 64-bit Unix timestamp conversions for 32-bit systems? I need to convert struct tm to 64-bit integer and vice versa, including leap years, time zones, UTC. Also need it portable, at least for GNU/Linux and Windows.


Solution

  • You need:

    typedef long long time64_t; 
    time64_t mktime64(struct tm *t); 
    struct tm* localtime64_r(const time64_t* t, struct tm* p);
    

    Originally (in 2011) this answer contained links to 2038bug.com where it was possible to download the small pivotal_gmtime_r library, containing the mentioned functions. The library has been removed from 2038bug.com back then, the links became broken and were removed from the answer by a moderator. Seems like that pivotal_gmtime_r code can now be found here:

    https://github.com/franklin373/mortage/tree/master/time_pivotal

    Also, I've found another, more recent library, called y2038, that also implements mktime64 and localtime64_r:

    https://github.com/evalEmpire/y2038