![]() |
VOOZH | about |
In C++, the <ctime> header provides the std::chrono::day class that represents a day in the given month. In this article, we will learn how to use the std::chrono::day class in C++.
The ::day class was introduced in C++ 20 to represent a day in a month. It is a duration-based representation of the day in the calendar month. It allows for the precise calculations and manipulations of the dates and time durations. It is particularly useful when dealing with calendar-related operations and when precise handling of the time intervals is required.
std::chrono::day d{day_count};
where:
Except for increment, equality and output operator overload, the std::chrono::day only have one member function named ok() which checks whether the value of the day object is in the valid range.
The following program illustrates how to use std::chrono::day in C++:
Output
Day of the month:- Today: 4 Tommorow: 5
Time Complexity: O(1)
Auxiliary Space: O(1)
Explanation: The above program fetches the current date and extracts the day of the month from it using the std::chrono::day class.
Note: This program will only work in C++ 20 or above versions.