- 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
Chrono in C++
In this section we will see what is the Chrono library in C++. This Chrono library is used for date and time. Timers and clocks are different in different systems. So if we want to improve time over precision we can use this library.
In this library, it provides precision-neutral concept, by separating the durations and point of time.
The duration objects are used to express time span by means of a count like minute, two hours or ten minutes. For example, 30 seconds is represented by a duration consisting of 30 ticks of unit of 1 seconds.
Example
#include <iostream> #include <chrono> using namespace std; int main () { using namespace std::chrono; // chrono::milliseconds is an instantiation of std::chrono::duration milliseconds mili(1000); mili = mili*60; cout << "Duration : "; cout << mili.count() << " milliseconds.\n"; cout << "Duration : "; cout << (mili.count() * milliseconds::period::num / milliseconds::period::den); cout << " seconds.\n"; }
Output
Duration : 60000 milliseconds. Duration : 60 seconds.
Advertisements