The function time() retrieves the current calendar time from the system's clock. It has the following prototype:

time_t time(time_t * tp);

In systems in which no clock is available, the function returns -1.

Part 1:
I found this on the internet. I have a question about the above quote where they mention there could be situation in which "no clock is available".

What do they mean by no clock availabe? For example I am running linux, doesn't all OS have some kind of clock?

Part 2:
I need to add some time interval to the current time, how I do this?

>>doesn't all OS have some kind of clock
Most do, but some embedded systems do not, for example the computers in your car do not have a clock (except, of course, the clock you see). A few years ago when we were all busy making Y2K adjustments to our programs auto manufacturers didn't have to change anything because their computers didn't have clocks. I know of a couple other embedded systems that don't have them either.

Part 2:
Depends. If you know the number of seconds then just add the seconds to the return value of time(). Otherwise, call localtime() to get a pointer to struct tm, change the number of hours, minutes or seconds you want to increment, then call mktime() to normalize the tm structure (make corrections). For example if you want to increment the current time by 9 hours then add 9 to the tm_hours structure member and don't worry if the result is greater than 24 because mktime() will make all necessary adjustments to the date and time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.