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
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/c-programming/time/c-time.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics