return now() as sys_seconds

Apr 3, 2023 at 3:26pm
I need the following function

1
2
3
4
 std::chrono::sys_seconds now() {
     const auto now_point = std::chrono::system_clock::now();
     return now_point;
    }



??
Apr 3, 2023 at 3:54pm
Is the following doing what you want?

1
2
3
4
std::chrono::sys_seconds now() {
    const auto now_point = std::chrono::system_clock::now();
    return std::chrono::time_point_cast<std::chrono::seconds>(now_point);
}
Apr 3, 2023 at 3:54pm
Perhaps:

1
2
3
4
[[nodiscard]]
inline auto now() {
	return std::chrono::time_point_cast<std::chrono::sys_seconds::duration>(std::chrono::system_clock::now());
}

Last edited on Apr 3, 2023 at 3:55pm
Apr 3, 2023 at 5:14pm
Excellent solutions!! Thanks !

Topic archived. No new replies allowed.