0

I am trying to build a expiration date on my .so library, and for that i wrote a simple program to find the better way. Below is my source code.

#include <iostream>
using namespace std;

int main (int argc, char ** argv)
{
    time_t now;
    struct tm expireDate = {0};
    double  seconds;
    expireDate.tm_hour =15;
    expireDate.tm_min = 0;
    expireDate.tm_sec = 0;
    expireDate.tm_year = 2016-1900;
    expireDate.tm_mon = 0;
    expireDate.tm_mday = 20;

    time(&now);
    seconds = difftime(mktime(&expireDate), now);
    cout<<"Diff time is "<< mktime(&expireDate) - now ;
    cout<<"Diff time is "<< seconds ;

}

Question:

1) The result of difftime() API is same as the result of subtracting 'now' from mktime(&expireDate). Is there any nifty things that difftime does?. Is it OK to just subtract rather using difftime() API?

DrunkenMaster
  • 1,218
  • 3
  • 14
  • 28

0 Answers0