i need to be able fill two variables (a kind of time variable), then be able to calculate their difference.
after all of my searches i found difftime
, but my problem is that, it uses time_t
variables, and i don't know how to fill a 'time_t' with time which i want.
for example i want to user enter time_1 and time_2 as (10:04, 11:05) and it be able to show difference in sec or minute or hour or anything.(for example 61 min)
i tried as blow but it didn't worked:
#include <iostream>
#include <ctime>
using namespace std;
void main()
{
tm time_1 = {0, 0, 0, 1, 0, 0, 0, 0, 0};
tm time_2 = {0, 0, 0, 1, 0, 0, 0, 0, 0};
time_1.tm_hour = 10;
time_1.tm_min = 4;
time_2.tm_hour = 11;
time_2.tm_min = 5;
double diff = difftime (mktime(&time_2),mktime(&time_1));
cout << diff << endl;
system("pause");
}