- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
localtime() function in C++
In this article we will be discussing the working, syntax and examples of localtime() function in C++ STL.
What is localtime()?
localtime() function is an inbuilt function in C++ STL, which is defined in the <ctime> header file. localtime() is used to convert the given time into the local time.
This function uses a value referred by the timer and fill the value of the structure and it converts the value into the given local timezone
Syntax
localtime(time_t *timer);
Parameters
The function accepts the following parameter(s) −
- timer − It is a pointer to objects which have the time_t type value.
Return value
This function returns a pointer pointing to the structure of the time which is stored in the local timezone.
Example
#include <bits/stdc++.h> using namespace std; int main(){ time_t hold; hold = time(NULL); tm* hold_local = localtime(&hold); cout<<"Current local time of system is: "<< hold_local->tm_hour << ":"<<hold_local->tm_min << ":"<<hold_local->tm_sec; return 0; }
Output
Current local time of system is: 8:28:57
Advertisements