Reputation:
Is there any date time module in c++?
I researched a bit in google and came to know about <ctime>
header file but it just went above my head.
Any other thing that can do my work?
Upvotes: 3
Views: 1787
Reputation: 131525
<chrono>
C++11
Starting with C++11, the standard library contains date & time utilities, available in the <chrono>
header, with constructs within the std::chrono
namespace.
Among these you will find:
the library is heavily templated, so that you can use a type of your choice for the raw representation (even floating-point types), and set your own resolution.
Example of use: How to get current time and date in C++?
Note that std::chrono
facilities are somewhat-compatible with the old <ctime>
header types. For example, the "system clock" class has methods for converting to and from the <ctime>
time representation, time_t
. This will be useful to you if you're combining C and C++ code, or need to expose a C interface somewhere; otherwise - try avoiding <ctime>
-based code.
C++20
The new standard version approved in 2020 added:
As commenters @AndyG and @doug suggest, Howard Hinnant is the "C++ date&time guy", and much of his work has actually gone into the standard - but not all of it.
Howard maintains a library/set-of-libraries of his own, named "Date".
It is based on C++11 <chrono>
, but its changes are not exactly what's been added in C++20; so especially useful if you're using C++17 or earlier. It adds:
I'm assuming that eventually, all the good stuff from here will get standardized, but that hasn't happened yet.
Upvotes: 7