c++ calculating elapsed seconds from 2 time moments
I am trying to calculate how much seconds has been passed from 2 time moments. My code:
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
int FH, FM, FS, SH, SM, SS;
cin >> FH >> FM >> FS >> SH >> SM >> SS;
tm t1,t2;
t1.tm_hour = FH;
t1.tm_min = FM;
t1.tm_sec = FS;
t1.tm_mon = 1;
t1.tm_mday = 1;
t2.tm_hour = SH;
t2.tm_min = SM;
t2.tm_sec = SS;
t2.tm_mon = 1;
t2.tm_mday = 1;
cout << difftime(mktime(&t2),mktime(&t1));
}
But it just keeps throwing 0. Input is as follows:
FH, FM, FS -> First moment hours,minutes,seconds
SH, SM, SS -> Second moments hours, minutes, seconds
from Recent Questions - Stack Overflow https://ift.tt/30gSfvu
https://ift.tt/eA8V8J
Comments
Post a Comment