|
<ctime>
time_t time ( time_t * timer );
Get current time
Get the current calendar time as a time_t object.
The function returns this value, and if the argument is not a null pointer, the value is also set to the object pointed by timer.
Parameters
- timer
- Pointer to an object of type time_t, where the time value is stored.
Alternativelly, this parameter can be a null pointer, in which case the parameter is not used, but a time_t object is still returned by the function.
Return Value
The current calendar time as a time_t object.
If the argument is not a null pointer, the return value is the same as the one stored in the location pointed by the argument.
If the function could not retrieve the calendar time, it returns a -1 value.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13
|
/* time example */
#include <stdio.h>
#include <time.h>
int main ()
{
time_t seconds;
seconds = time (NULL);
printf ("%ld hours since January 1, 1970", seconds/3600);
return 0;
}
|
Possible output:
266344 hours since January 1, 1970
|
See also
asctime | Convert tm structure to string (function) |
gmtime | Convert time_t to tm as UTC time (function) |
localtime | Convert time_t to tm as local time (function) |
|