I want to get date with time that is 2 hours ahead. Currently I am trying this: where I add 2 to the hours value
void printTodayFutureTime()
{
char finalDate[50];
time_t t;
struct tm *date;
memset(finalDate, '\0', 50);
t = time(NULL);
date = localtime(&t);
if(date == NULL)
{
printf("Unable to get localtime\n\n");
return;
}
int today = date->tm_mday;
int month = date->tm_mon + 1;
int year = date->tm_year + 1900;
int hour = date->tm_hour;
int minute = date->tm_min;
int sec = date->tm_sec;
snprintf(finalDate, 50, "%d-%d-%dT%d:%d:%d", year, month, today, hour + 2, minute, sec);
printf("Today's date with future time is: %s\n\n", finalDate);
}
But this will not work if the hour is lets say 22, 23 because it will jump to hour 24 and 25... Can anyone please give me some advice or help.