time() function in C
The time() function is defined in time.h (ctime in C++) header file. This function returns the time since 00:00:00 UTC, January 1, 1970 (Unix timestamp) in seconds. If second is not a null pointer, the returned value is also stored in the object pointed to by second.
Syntax:
time_t time( time_t *second )
Parameter: This function accepts single parameter second. This parameter is used to set the time_t object which store the time.
Return Value: This function returns current calender time as a object of type time_t.
Program 1:
// C program to demonstrate // example of time() function. #include <stdio.h> #include <time.h> int main () { time_t seconds; seconds = time(NULL); printf("Seconds since January 1, 1970 = %ld\n", seconds); return(0); } |
Seconds since January 1, 1970 = 1538123990
Example 2:
// C program to demonstrate // example of time() function. #include <stdio.h> #include <time.h> int main() { time_t seconds; // Stores time seconds time(&seconds;); printf("Seconds since January 1, 1970 = %ld\n", seconds); return 0; } |
Seconds since January 1, 1970 = 1538123990
Recommended Posts:
- How to measure time taken by a function in C?
- time.h localtime() function in C with Examples
- Time delay in C
- time.h header file in C with Examples
- Measure execution time with high precision in C/C++
- C program to print digital clock with current time
- Sorting integer data from file and calculate execution time
- Cvent Interview Experience (On campus for Internship and Full Time)
- arc function in C
- putchar() function in C
- Inline function in C
- wcsncat() function in C/C++
- wcsncmp() function in C/C++
- wcsrtombs() function in C/C++
- wcstod() function in C/C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


