Hi all,
#include<ctime>
#include<string>
int main()
{
string snapshot_time = "10:00:00"
int interval = 60;
string end_time = convert_hour(snapshot_time,interval);
cout << end_time << endl;
}
string convert_hour(string &snapshot_time, int interval)
{
char current_time[BUFSIZ] = { '\0' } ;
struct tm tm;
strptime(snapshot_time.c_str(), "%H:%M:%S", &tm);
tm.tm_sec = tm.tm_sec + interval;
time_t t = mktime(&tm);
strftime( current_time, BUFSIZ, "%H:%M:%S", &tm) ;
return current_time;
}
I expect the output of my program to be 10:01:00 but it displays as 10:00:60.
Where am I going wrong? Thanks a lot in advance.