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