Easy Tutorial
❮ Cpp Pointer To An Array Increment Decrement Operators Overloading ❯

C Library Function - time()

C Standard Library - <time.h>

Description

The C library function timet time(timet *seconds) returns the time since the Epoch (1970-01-01 00:00:00 UTC) in seconds. If seconds is not NULL, the return value is also stored in the variable seconds.

Declaration

Here is the declaration for the time() function.

time_t time(time_t *seconds)

Parameters

Return Value

Returns the current calendar time as a time_t object.

Example

The following example demonstrates the use of the time() function.

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

int main ()
{
  time_t seconds;

  seconds = time(NULL);
  printf("Hours since 1970-01-01 = %ld\n", seconds/3600);

  return(0);
}

Let's compile and run the above program, which will produce the following result:

Hours since 1970-01-01 = 373711

C Standard Library - <time.h>

❮ Cpp Pointer To An Array Increment Decrement Operators Overloading ❯