samedi 12 juin 2021

How to find Time Duration between two dates with Hours minutes and seconds in C++ 11?

I need to find the time difference between two given dates.

I have tried the following code but not able to convert it into hours mins secs

         const char *time_details = "06/10/2021 16:35:12";
struct tm tm;
strptime(time_details, "%m/%d/%Y %H:%M:%S", &tm); // Prev date

time_t t = mktime(&tm);

const char *time_details1 = "06/11/2021 14:35:12";
struct tm tm1;
strptime(time_details1, "%m/%d/%Y %H:%M:%S", &tm1); // future date

time_t t33 = mktime(&tm1);

int timediff1 = difftime(t33,t);

    int seconds1 = timediff1%60;
int hour1 =seconds1/ 3600;
int minutes1 = seconds1 / 60 ;

The above always shows '0' in hours mins seconds. But getting some value in

Aucun commentaire:

Enregistrer un commentaire