time

The time function returns information about the current time. The parameter is a pointer to a variable of type time_t, where the result will be stored. This value can be NULL.

The return value of the time function is also a time_t value. It should have the same value is what is stored in the time_t parameter. In the case that the argument to time_t is NULL, this is the only way to recover the returned value.

Using the returned value

In general, the time_t value returned by time_t is an integral value where the current time has been encoded. To display the current time it is necessary to use one of the related functions, such as ctime or asctime.

Example

The following code shows an example of the time function:

#include <stdio.h>
#include <time.h>

int main()
{
        time_t t;
        t = time(NULL);
        printf("the current time is %s\n", ctime(&t));
        return 0;
}
Article created on 2008-08-19 22:24:57
coliv2 Said:
The time function is really very useful.
Comment added at 2008-12-07 18:20:00

Post a comment