C library function - time()

Advertisements


Description

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

Declaration

Following is the declaration for time() function.

time_t time(time_t *t)

Parameters

  • seconds -- This is the pointer to an object of type time_t, where the seconds value will be stored.

Return Value

The current calendar time as a time_t object.

Example

The following example shows the usage of time() function.

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

int main ()
{
  time_t seconds;

  seconds = time(NULL);
  printf("Hours since January 1, 1970 = %ld\n", seconds/3600);
  
  return(0);
}

Let us compile and run the above program, this will produce the following result:

Hours since January 1, 1970 = 373711


Advertisements
Advertisements