The portable way is to use the functions in time.h. 1. get current time using time() function, which returns the number of seconds since some pre-determined data, normally 1 Jun 1970. '
2. call localtime() to get a pointer to struct tm, which contains each element of date/time as integers.
3. Add the number of minutes to the tm_min element of tm structure.
4. call mktime() to normalize the date/time. This function corrects all tm structure members.
5. using final version of tm structure to print out the results.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>>if i add one minute in the struct tm and then call mktime() it will fix all the other members?{
Yes -- that is what normalize means
time() function returns a time_t (normally unsigned integer). If all you want to do is add minutes, then just add (minutes * 60) to the value returned by time(), then call localtime() to get the structure.
Yes, you can do that in two functions if you want.
Here is basically the way you will probably want to implement the algorithm. Your function aa() might get the number of minutes from the keyboard, then pass that value to bb() to display the date/time.
int number_minutes = 1;
time_t today = time(0);
// add 1 minute to the current date/time
today += (60 * number_minutes);
struct tm* tm = localtime(&todlay);
// now just print out the struct tm
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Why do you need a toString function? cout will print out the integers quite well
cout << tm->tm_hour << ;
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343