std::chrono...ss::hh_mm_ss(3)
πΈ NAME πΈ
std::chrono::hh_mm_ss::hh_mm_ss β bestie, it's the constructor of std::chrono::hh_mm_ss, the literal glow-up that turns a duration into hours/minutes/seconds/subseconds π
(oh and hey, this page lives in the C++ Standard Libary manual β spelling's theirs, not mine π«Ά)
β¨ Synopsis β¨
Two flavors, both constexpr, okay? Here's the whole thing, verbatim, no cap:
constexpr hh_mm_ss() noexcept : hh_mm_ss{Duration::zero()} {} (1)
constexpr explicit hh_mm_ss( Duration d ); (2)
Both of them construct a hh_mm_ss object. Iconic. Obsessed.
- This one constructs a
hh_mm_ssobject corresponding toDuration::zero(). Zero. Nothing. The β¨clean slateβ¨ era. Also it'snoexcept, so she will not be throwing tantrums. - This one constructs a
hh_mm_ssobject corresponding tod, and here's the breakdown that ate, fr fr:is_negative()returnsd < Duration::zero().hours()returnsstd::chrono::duration_cast<std::chrono::hours>(abs(d)).minutes()returnsstd::chrono::duration_cast<std::chrono::minutes>(abs(d) - hours()).seconds()returnsstd::chrono::duration_cast<std::chrono::seconds>(abs(d) - hours() - minutes()).subseconds()returnsabs(d) - hours() - minutes() - seconds()ifstd::chrono::treat_as_floating_point_v<precision::rep>istrue; otherwise it returnsstd::chrono::duration_cast<precision>(abs(d) - hours() - minutes() - seconds()).
π«Ά little heads-up: constructor (2) is explicit, so no sneaky implicit conversions happening on your watch. She said boundaries.
π Parameters π
dβ the duration to be broken down π (she's getting dismantled, respectfully)
π¦ Example π¦
// Run this code
#include <chrono>
#include <print>
int main()
{
std::println("Default constructor: {}",
std::chrono::hh_mm_ss<std::chrono::minutes>{});
std::chrono::time_point now = std::chrono::system_clock::now();
std::chrono::hh_mm_ss time_of_day{now -
std::chrono::floor<std::chrono::days>(now)};
std::println("The time of day is: {}", time_of_day);
}
π Possible output:
Default constructor: 00:00:00
The time of day is: 12:13:14.151617189
(your nanosecond tail will absolutely vary, that's just the universe being quirky π)
okay that's the whole page, main character energy complete π β sourced from http://cppreference.com, version 2024.06.10, the std::chrono...ss::hh_mm_ss(3) page. bye bestie, go format some durations ππβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms