Search code examples
c++cross-platformepochmktime

Get number of days since epoch in C++ (cross platform)


How can i get count of days since epoch in C++, i know that i should use mktime function, but i cant understand how to implement it

Thanks!


Solution

  • Modifying some sample code from cplusplus.com:

    #include <stdio.h>
    #include <time.h>
    
    int main ()
    {
      time_t seconds;
    
      seconds = time (NULL);
      int daysSinceEpoch = seconds/(60*60*24);
      printf ("%ld days since January 1, 1970", daysSinceEpoch);
    
      return 0;
    }