- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 library 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 Code
#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.
- Related Articles
- Chrono in C++
- Library in C++ STL?
- wprintf() and wscanf in C Library
- Any datatype in C++ boost library
- isgraph() C library function
- Difftime() C library function
- Wide char and library functions in C++
- Multiset in C++ Standard Template Library (STL)
- Pair in C++ Standard Template Library (STL)
- Sort in C++ Standard Template Library (STL)
- Advanced C++ with boost library
- C++ Standard Library Header Files
- Binary Search in C++ Standard Template Library (STL)
- Priority Queue in C++ Standard Template Library (STL)
- The C++ Standard Template Library (STL)

Advertisements