std::chrono::operator==,<=>(std::chrono::year_month_day)
来自cppreference.com
< cpp | chrono | year month day
工具库
日期和时间工具
时间点 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
时长 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
时钟 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
当天时刻 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
日历 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
时区 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
chrono I/O |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++20)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
C 风格日期和时间 |
std::chrono::year_month_day
成员函数 | ||||
非成员函数 | ||||
operator==operator<=>
|
||||
辅助类 | ||||
在标头
<chrono>
定义
|
||
constexpr bool operator==( const std::chrono::year_month_day& x,
const std::chrono::year_month_day& y ) noexcept; |
(1) | (C++20 起) |
constexpr
std::strong_ordering
operator<=>(
const std::chrono::year_month_day&
x, |
(2) | (C++20 起) |
比较二个 year_month_day
值 x
与 y
。这是字典序比较:首先比较 year() ,然后是 month() ,最后比较 day() 。
<
、 <=
、 >
、 >=
及 !=
运算符分别从 operator<=>
与 operator==
合成。
返回值
1) x.year() == y.year() && x.month() == y.month() && x.day() == y.day()
2) 若 x.year() <=>
y.year !=
0 则为 x.year() <=>
y.year ;否则若 x.month() <=>
y.month()
!= 0 则为 x.month() <=>
y.month() ;否则为 x.day() <=>
y.day()
注解
若 x
和 y
都表示合法日期( x.ok() &&
y.ok() == true
),则字典序比较的结果与日历顺序一致。
示例
运行此代码
#include <iostream> #include <chrono> int main() { constexpr auto ymd1 {std::chrono::day(1)/7/2021}; constexpr auto ymd2 {std::chrono::year(2021)/7/1}; std::cout << std::boolalpha << (ymd1 == ymd2) << '\n'; static_assert(ymd1 <= ymd2); }
输出:
true