std::chrono::is_am, std::chrono::is_pm, std::chrono::make12, std::chrono::make24

From cppreference.com
< cpp‎ | chrono
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

Elementary string conversions
(C++17)
(C++17)
 
Date and time utilities
(C++11)
(C++11)
Time of day
(C++20)



is_amis_pmmake12make24
(C++20)(C++20)(C++20)(C++20)
Clocks
(C++20)
                                             
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
Calendars
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
Time zones
(C++20)
(C++20)
(C++20)
(C++20)
C-style date and time
 
Defined in header <chrono>
constexpr bool is_am( const std::chrono::hours& h ) noexcept;
(1) (since C++20)
constexpr bool is_pm( const std::chrono::hours& h ) noexcept;
(2) (since C++20)
constexpr std::chrono::hours make12( const std::chrono::hours& h ) noexcept;
(3) (since C++20)
constexpr std::chrono::hours make24( const std::chrono::hours& h,
                                     bool is_pm ) noexcept;
(4) (since C++20)

These functions aid in translating between a 12-hour format time of day, and a 24-hour format time of day.

1) Detects whether the 24-hour format time is a.m. (ante meridiem, before midday).
2) Detects whether the 24-hour format time is p.m. (post meridiem, after midday).
3) Returns the 12-hour equivalent of a 24-hour format time.
4) Returns the 24-hour equivalent of a 12-hour format time h, where is_pm determines whether the time is p.m.

Parameters

h - 12-hour or 24-hour format time to detect
is_pm - whether the 12-hour format time is p.m.

Return value

1) 0h <= h && h <= 11h.
2) 12h <= h && h <= 23h.
3) If h is in range [0h, 23h], returns the 12-hour equivalent in range [1h, 12h]. Otherwise, the return value is unspecified.
4) If h is in range [1h, 12h], returns the 24-hour equivalent in range [0h, 11h] if is_pm is false, or in range [12h, 23h] otherwise. Otherwise, the return value is unspecified.

Example