localtime() function in C++
The localtime() function is defined in the ctime header file. The localtime() function converts the given time since epoch to calendar time which is expressed as local time.
Syntax:
tm* localtime(const time_t* time_ptr);
Parameter: This function accepts a parameter time_ptr which represents the pointer to time_t object.
Return Value: This function returns a pointer to a tm object on success, Otherwise it returns NullPointerException.
Below program illustrate the localtime() function in C++:
Example:-
// c++ program to demonstrate // example of localtime() function. #include <bits/stdc++.h> using namespace std; int main() { time_t time_ptr; time_ptr = time(NULL); // Get the localtime tm* tm_local = localtime(&time;_ptr); cout << "Current local time is = " << tm_local->tm_hour << ":" << tm_local->tm_min << ":" << tm_local->tm_sec; return 0; } |
Current local time is = 10:8:10
Recommended Posts:
- How to call some function before main() function in C++?
- Function Overloading vs Function Overriding in C++
- Difference between Virtual function and Pure virtual function in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- div() function in C++
- log() function in C++
- exp() function C++
- fma() function in C++
- clock() function in C/C++
- c16rtomb() function in C/C++
- c32rtomb() function in C/C++
- strtoimax() function in C++
- nearbyint() function in C++
- mbrlen() function in C/C++
- mbrtowc() 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.

