Currently I am trying to add minutes to current time, but how do I do it? I read through some tutorials and all but still have no idea how to do it.
So my code goes..
time_t now = time(0);
tm* localtm = localtime(&now);
cout << "Current time : " << asctime(localtm) << endl;
My program will sort of "run" in minutes which is + 1 minute every loop..
So lets say there is 255 loops and it is 255 minutes.. I store it in Minute.
I tried adding it this way but the time remained the same as the current time..
localtm->tm_min + Minute;
mktime (localtm);
cout << "End of program time : " << asctime(localtm) << endl;
I am wondering how should I do it. Can anyone help?
int main()
{
time_t now = time(0);
size_t Minutes = 255;
time_t newTime = now + (60 * Minutes);
struct tm tNewTime;
memset(&tNewTime, '\0', sizeof(struct tm));
localtime_r(&newTime, &tNewTime);
cout << asctime(&tNewTime) << endl;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With