std::chrono::operator+, std::chrono::operator- (std::chrono::year_month)
来自cppreference.com
< cpp | chrono | year month
工具库
日期和时间工具
| 时间点 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 时长 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 时钟 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 当天时刻 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 日历 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 时区 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
chrono
I/O
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++20)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| C 风格日期和时间 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
constexpr
std::chrono::year_month
operator+(const
std::chrono::year_month&
ym,
const std::chrono::years& dy) noexcept; |
(1) | (C++20 起) |
|
constexpr
std::chrono::year_month
operator+(const
std::chrono::years&
dy,
const std::chrono::year_month& ym) noexcept; |
(2) | (C++20 起) |
|
constexpr
std::chrono::year_month
operator+(const
std::chrono::year_month&
ym,
const std::chrono::months& dm) noexcept; |
(3) | (C++20 起) |
|
constexpr
std::chrono::year_month
operator+(const
std::chrono::months&
dm,
const std::chrono::year_month& ym) noexcept; |
(4) | (C++20 起) |
|
constexpr
std::chrono::year_month
operator-(const
std::chrono::year_month&
ym,
const std::chrono::years& dy) noexcept; |
(5) | (C++20 起) |
|
constexpr
std::chrono::year_month
operator-(const
std::chrono::year_month&
ym,
const std::chrono::months& dm) noexcept; |
(6) | (C++20 起) |
|
constexpr
std::chrono::months
operator-(const
std::chrono::year_month&
ym1,
const std::chrono::year_month& ym2) noexcept; |
(7) | (C++20 起) |
1-2) 加上
dy.count() 年到
ym 。3-4) 加上
dm.count() 月到
ym 。5) 从
ym 减去
dy.count() 年。6) 从
ym 减去
dm.count() 月。7) 返回
ym1 与
ym2 所表示的二个时间点间以 months 计量的差。对于能转换到 std::chrono::years 与 std::chrono::months 两者的时长,若调用有歧义,则偏好
years 重载 (1,2,5) 。
返回值
1-2) std::chrono::year_month(ym.year()
+ dy, ym.month())
3-4) A
year_month
value z such that z - ym == dm5) ym + -dy
6) ym + -dm
7) ym1.year()
- ym2.year()
+ std::chrono::months(int(unsigned(ym1.month()))
- int(unsigned(ym2.month())))
注解
二个 year_month 值相减的结果是 std::chrono::months 类型时长。此时长单位表示格里高利月的平均长度(
30.436875 日),而产生的时长与问题中的实际日数无关。例如 2017y/3
- 2017y/2 的结果是 std::chrono::months(1) ,即使 2017
年二月只含 28 日。
示例
| 本节未完成 原因:暂无示例 |
参阅
以一定量的月和年为程度修改 year_month (公开成员函数) |