Reputation: 87
hi i was wondering if it is possible to edit the time function.for my program to give a time for a user to retry again?
struct tm * abc()
{
char *time_string;
time_t curtime;
struct tm *loctime;
/* Get the current time. */
curtime = time (NULL);
/* Convert it to local time representation. */
loctime = localtime (&curtime);
return loctime;
}
this will return the current time but want i want to do is to edit this to add a value. The reason for me doing this is so i can tell a user to try again at a certain time using the current and adding 2minutes to it. Not sure if this is the correct way? Thanks
Upvotes: 0
Views: 4011
Reputation: 70979
Add the following lines just before the return.
localtime->tm_min += 2;
mktime(localtime);
The first line adds two minutes to localtime. The second line renormalizes localtime to a "standard" format, in other words you it will roll the added minutes from values like (61) to values like (hours+1),(minutes = 1).
Upvotes: 0