w3resource

C time() function

C time() function - Get time

Syntax:

time_t time(time_t *t)

The time() function is used to determine the current calendar time, in seconds.

Parameters:

Name Description Required /Optional
seconds Pointer to the storage location for time. Required

Return value from time() function

  • Upon successful completion, time() shall return the value of time.
  • Otherwise, (time_t)-1 shall be returned.

Example: time() function

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


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

int main(void)
{
time_t result;
    result = time(NULL);
    printf("%s%ju secs since the Epoch\n",
        asctime(localtime(&result)),result);
    return(0);
}

Output:

Tue Dec 20 18:54:38 2022
1671542678 secs since the Epoch

C Programming Code Editor:

Previous C Programming: C strftime()
Next C Programming: C time.h Home



Follow us on Facebook and Twitter for latest update.