Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
ciso646 (iso646.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
ctime (time.h)
functions:
asctime
clock
ctime
difftime
gmtime
localtime
mktime
strftime
time
macros:
CLOCKS_PER_SEC
NULL
types:
clock_t
size_t
time_t
struct tm


time

function
<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