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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- How to measure time taken by a function in C?
- time.h localtime() function in C with Examples
- Time delay in C
- C program to print digital clock with current time
- Cvent Interview Experience (On campus for Internship and Full Time)
- Measure execution time with high precision in C/C++
- Sorting integer data from file and calculate execution time
- time.h header file in C with Examples
- C program for Time Complexity plot of Bubble, Insertion and Selection Sort using Gnuplot
- How to call function within function in C or C++
- Write a one line C function to round floating point numbers
- Does C support function overloading?
- How can I return multiple values from a function?
- What is the purpose of a function prototype?
- How to declare a pointer to a function?
- C function to Swap strings
- Can we call an undeclared function in C++?
- What is evaluation order of function parameters in C?
- Can we use function on left side of an expression in C and C++?
- Function Pointer in 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.

