operator+
下列類型的加法運算子:
daydurationmonthtime_pointweekdayyearyear_monthyear_month_dayyear_month_day_lastyear_month_weekdayyear_month_weekday_last
1)
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
operator+(
const duration<Rep1, Period1>& Left,
const duration<Rep2, Period2>& Right);
2)
template <class Clock, class Duration1, class Rep2, class Period2>
constexpr time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
operator+(
const time_point<Clock, Duration1>& Time,
const duration<Rep2, Period2>& Dur);
3)
template <class Rep1, class Period1, class Clock, class Duration2>
time_point<Clock, constexpr typename common_type<duration<Rep1, Period1>, Duration2>::type>
operator+(
const duration<Rep1, Period1>& Dur,
const time_point<Clock, Duration2>& Time);
4)
constexpr day operator+(const day& d, const days& ds) noexcept; // C++20
constexpr day operator+(const days& ds, const day& d) noexcept; // C++20
5)
constexpr month operator+(const month& m, const months& ms) noexcept; // C++20
constexpr month operator+(const months& ms, const month& m) noexcept; // C++20
6)
constexpr weekday operator+(const weekday& wd, const days& wds) noexcept // C++20
constexpr weekday operator+(const days& ds, const weekday& wd) noexcept; // C++20
7)
constexpr year operator+(const year& y, const years& ys) noexcept; // C++20
constexpr year operator+(const years& ys, const year& y) noexcept; // C++20
8)
constexpr year_month operator+(const year_month& ym, const months& dm) noexcept; // C++20
constexpr year_month operator+(const months& dm, const year_month& ym) noexcept; // C++20
constexpr year_month operator+(const year_month& ym, const years& dy) noexcept; // C++20
constexpr year_month operator+(const years& dy, const year_month& ym) noexcept; // C++20
9)
constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept; // C++20
constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept; // C++20
constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept; // C++20
constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept; // C++20
10)
constexpr year_month_day_last operator+(const year_month_day_last& ymdl, const months& dm) noexcept; // C++20
11)
constexpr year_month_day_last operator+(const months& dm, const year_month_day_last& ymdl) noexcept; // C++20
12)
constexpr year_month_day_last operator+(const year_month_day_last& ymdl, const years& dy) noexcept; // C++20
constexpr year_month_day_last operator+(const years& dy, const year_month_day_last& ymdl) noexcept; // C++20
13)
constexpr year_month_weekday operator+(const year_month_weekday& ymwd, const months& dm) noexcept; // C++20
constexpr year_month_weekday operator+(const months& dm, const year_month_weekday& ymwd) noexcept; // C++20
14)
constexpr year_month_weekday operator+(const year_month_weekday& ymwd, const years& dy) noexcept; // C++20
15)
constexpr year_month_weekday operator+(const years& dy, const year_month_weekday& ymwd) noexcept; // C++20
16)
constexpr year_month_weekday_last operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept; // C++20
constexpr year_month_weekday_last operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept; // C++20
17)
constexpr year_month_weekday_last operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept; // C++20
constexpr year_month_weekday_last operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept; // C++20
傳回值
1) 在轉換成LeftRight其通用型別之後,傳回duration的刻度計數等於已轉換刻度計數總和的 。
2-3) 傳回 time_point 物件,代表從時間Dur點取代Time間隔的時間點。
4) 傳回 的結果 d+ds.count()。 如果結果超出範圍 [0, 255],則結果不會指定。
5) 傳回 的結果 m+ms.count()。 如果結果超出範圍 [1, 12],則會降低模數 12,然後是 +1。
6) 傳回將天數和工作日新增至 weekday的結果。 結果會是模數 7,因此一律在範圍 [0,6]
7) 傳回將年份加入指定年份數目的結果。
8) 傳回將月份和年數新增至指定月份和年份的結果。
9) 傳回將月份或年份加入 至 year_month_day的結果。 如果 ymd.month() 是 February 且 ymd.day() 不在範圍 [1d, 28d]中, ok() 可能會傳回 false 加法的結果。
10) 傳回 (ymdl.year() / ymdl.month() + dm) / last。 注意: / 此處使用的 不是除法運算符。 這是日期運算符。
11) 傳回 ymdl + dm。
12) 傳回 {ymdl.year()+dy, ymdl.month_day_last()}
13) 傳回 ymwd + dm.count()。
14-15) 傳回 {ymwd.year()+dy, ymwd.month(), ymwd.weekday_indexed()}。
16) 傳回 (ymwdl.year() / ymwdl.month() + dm) / ymwdl.weekday_last()。 注意: / 此處使用的 不是除法運算符,而是日期運算符。
17) 傳回: ymwdl + dy
範例: operator+
// compile using: /std:c++latest
#include <iostream>
#include <chrono>
using namespace std::chrono;
int main()
{
// day
day d{1};
std::cout << d + days(2) << '\n'; // 03
// month
month m{11};
std::cout << m + months(3)<< '\n'; // Feb
// weekday
weekday wd = Thursday;
std::cout << wd + days(1) << '\n'; // Fri
// year_month_day_last
year_month_day_last ymdl{June / last / 2021};
std::cout << ymdl + years{1} + months{1} << '\n'; // 2022/Jul/last
// year_month_weekday
year_month_weekday ymw{ year(1997) / January / Wednesday[1] };
std::cout << ymw + months{1} << '\n'; // 1997/Feb/Wed[1]
std::cout << ymw + years{1} << '\n'; // 1998/Jan/Wed[1]
// year_month_weekday_last
year_month_weekday_last ymwl{ year(1997) / January / Wednesday[last] };
std::cout << ymwl + months{ 1 } << '\n'; // 1997/Feb/Wed[last]
std::cout << ymwl + years{ 1 } << '\n'; // 1998/Jan/Wed[last]
return 0;
}
03
Feb
Fri
2022/Jul/last
1997/Feb/Wed[1]
1998/Jan/Wed[1]
1997/Feb/Wed[last]
1998/Jan/Wed[last]
元 operator+
將一元加號套用至下列型態:
// duration
constexpr common_type_t<duration> operator+() const // C++20
傳回值
傳回 *this。
operator-
下列類型的減法運算子:
daydurationmonthtime_pointweekdayyearyear_monthyear_month_dayyear_month_day_lastyear_month_weekdayyear_month_weekday_last
1)
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
operator-(
const duration<Rep1, Period1>& Left,
const duration<Rep2, Period2>& Right);
2)
template <class Clock, class Duration1, class Rep2, class Period2>
constexpr time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type
operator-(
const time_point<Clock, Duration1>& Time,
const duration<Rep2, Period2>& Dur);
3)
template <class Clock, class Duration1, class Duration2>
constexpr typename common_type<Duration1, Duration2>::type
operator-(
const time_point<Clock, Duration1>& Left,
const time_point<Clock, Duration2>& Right);
4)
constexpr day operator-(const day& d, days& ds) noexcept; // C++20
constexpr day operator-(const day& d, const day& d) noexcept; // C++20
5)
constexpr month operator-(const month& m, const months& ms) noexcept; // C++20
constexpr month operator-(const month& m, const month& ms) noexcept; // C++20
6)
constexpr months operator-(const year_month& Left, const year_month& Right) noexcept; // C++20
7)
constexpr weekday operator-(const weekday& Left, const days& Right) noexcept; // C++20
8)
constexpr days operator-(const weekday& Left, const weekday& Right) noexcept; // C++20
9)
constexpr year operator-(const year& y, const years& ys) noexcept; // C++20
10)
constexpr years operator-(const year& y, const year& y2) noexcept; // C++20
11)
constexpr year_month operator-(const year_month& ym, const months& dm) noexcept; // C++20
constexpr year_month operator-(const year_month& ym, const years& dy) noexcept; // C++20
12)
constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept; // C++20
constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept; // C++20
13)
constexpr year_month_day_last operator-(const year_month_day_last& ymdl, const months& dm) noexcept; // C++20
14)
constexpr year_month_day_last operator-(const year_month_day_last& ymdl, const years& dy) noexcept; // C++20
15)
constexpr year_month_weekday operator-(const year_month_weekday& ymwd, const months& dm) noexcept; // C++20
16)
constexpr year_month_weekday operator-(const year_month_weekday& ymwd, const years& dy) noexcept; // C++20
17)
constexpr year_month_weekday_last operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept; // C++20
18)
constexpr year_month_weekday_last operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept; // C++20
傳回值
1) 將減去的持續時間轉換成其一般型別之後,傳回duration的刻度計數等於 中刻度數減去的刻度RightLeft數目。
2) 傳回 time_point ,代表從 所DurTime指定時間點取代的時間間隔否定所取代的時間點。
3) 傳回 duration 物件,表示 與Left之間的Right時間間隔。
4) 傳回 的結果 d-ds.count()。 如果結果超出範圍 [0, 255],則結果不會指定。
5) 如果 m.ok() == true 和 ms.ok() == true,會傳回減去兩個月值的結果,或減去月數。 結果會在 [1, 12] 範圍內。 如果結果為負數,則會四處換行。 例如,從1月減去一個月(month m1{1} - months{1}; 結果為12月(12月)。
6) 傳回 和之間的 Left 月份差異 Right
7) 如果 Left.ok() == true 和 ,則會Right.ok() == true傳回範圍 [weekday, days{0}] 中的 。days{6}
8) 傳回兩個工作日之間的天數。
9) 傳回 year(int(y)-ys.count())
10) 傳回 years(int(y) - int(y2))。 減去兩year個std::chrono::years值會產生 ,這表示 和y之間的y2年份差異。 範例:2021y-2000y 會產生 years(21)。
11) 傳回值減去月份或年份 year_month 的結果。
12) 傳回從 值減去月份年 year_month_day 的結果。
13) 傳回從 值減去月 year_month_day_last 數的結果。 基本上: ymdl-dm。
14) 傳回從 值減去年 year_month_day_last 數的結果。 基本上: ymdl-dy。
15) 傳回從 值減去月份 year_month_weekday 數的結果。 基本上: ymwd-dm。
16) 傳回從 值減去年 year_month_weekday 數的結果。 基本上: ymwd-dy。
17) 傳回從 值減去月份 year_month_weekday_last 數的結果。 基本上: ymwdl-dm。
18) 傳回從 值減去年 year_month_weekday_last 數的結果。 基本上: ymwdl-dy。
範例: operator-
// compile using: /std:c++latest
#include <iostream>
#include <chrono>
using namespace std::chrono;
int main()
{
// day
day d{10};
d = d - days(5);
std::cout << d << '\n'; // 05
// month
month m{2};
m = m - months{1};
std::cout << m << '\n'; // Jan
m = m - months{1};
std::cout << m << '\n'; // Dec
// year
auto diff1 = 2021y-2000y;
auto diff2 = 2021y-years{1};
std::cout << diff1.count() << '\n'; // 21
std::cout << diff2 << '\n'; // 2020
// year_month
const year theYear{ 2021 };
year_month ym1{theYear, June};
year_month ym2 = ym1 - months{2};
std::cout << ym2 << '\n'; // 2021/Apr
year_month ym3 = ym1 - years{2};
std::cout << ym3 << '\n'; // 2019/Jun
// year_month_day_last
year_month_day_last ymdl = June / last / 2021;
std::cout << ymdl - years{1} - months{1} << '\n'; // 2020/May/last
// year_month_weekday
year_month_weekday ymw{ year(1997) / January / Wednesday[1] };
std::cout << ymw - months{1} << '\n'; // 1996/Dec/Wed[1]
std::cout << ymw - years{1} << '\n'; // 1996/Jan/Wed[1]
// year_month_weekday_last
year_month_weekday_last ymwl{ year(1997) / January / Wednesday[last] };
std::cout << ymwl - months{ 1 } << '\n'; // 1996/Dec/Wed[last]
std::cout << ymwl - years{ 1 } << '\n'; // 1996/Jan/Wed[last]
return 0;
}
05
Jan
Dec
21
2020
2021/Apr
2019/Jun
2020/May/last
1996/Dec/Wed[1]
1996/Jan/Wed[1]
1996/Dec/Wed[last]
1996/Jan/Wed[last]
元 operator-
否定。duration
constexpr common_type_t<duration> operator-() const;
傳回值
傳回的否定複本 *this
範例:一元 operator-
// compile using: /std:c++latest
#include <iostream>
#include <chrono>
using namespace std::chrono;
int main()
{
duration<int, std::milli> milliseconds(120);
std::cout << -milliseconds << '\n';
return 0;
}
-120ms
operator!=
判斷是否:
1) 兩個 duration 物件不代表相同數目的刻度。
2) 兩個 time_point 物件不代表相同的時間點。
1)
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr bool operator!=(
const duration<Rep1, Period1>& Left,
const duration<Rep2, Period2>& Right);
2)
template <class Clock, class Duration1, class Duration2>
constexpr bool operator!=(
const time_point<Clock, Duration1>& Left,
const time_point<Clock, Duration2>& Right);
參數
Left
左邊的 duration 或 time_point 物件。
Right
右邊的 duration 或 time_point 物件。
傳回值
1) 如果通用且trueLeft不相等的型別刻度數,則傳Right回 。 否則傳回 false。
2) 如果兩個true物件不代表相同的時間點,則傳time_point回 。 否則傳回 false。
operator*
duration 物件的乘法運算子。 將 durations 乘以其通用型別之後,傳回 duration 的刻度計數等於所轉換刻度計數乘法的 。
1)
template <class Rep1, class Period1, class Rep2>
constexpr duration<typename common_type<Rep1, Rep2>::type, Period1>
operator*(
const duration<Rep1, Period1>& Dur,
const Rep2& Mult);
2)
template <class Rep1, class Rep2, class Period2>
constexpr duration<typename common_type<Rep1, Rep2>::type, Period2>
operator*(
const Rep1& Mult,
const duration<Rep2,
Period2>& Dur);
參數
Dur
duration 物件。
Mult
整數值。
傳回值
傳回物件 duration ,其間隔長度 Mult 乘以 的 Dur長度。
1) 除非 is_convertible<Rep2, common_type<Rep1, Rep2>>保留 true,否則此函式不會參與多載解析。 如需詳細資訊,請參閱 <type_traits>。
2) 除非 is_convertible<Rep1, common_type<Rep1, Rep2>>保留 true,否則此函式不會參與多載解析。 如需詳細資訊,請參閱 <type_traits>。
operator<
1) 轉換 duration的 比較其一般類型之後,判斷 的刻度 Left 數目是否小於 Right。
2) 判斷 自 的 Epoch Lefttime_point 以來的時間點是否小於 中 time_point之 Epoch Right 的時間點。
1)
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr bool operator<(
const duration<Rep1, Period1>& Left,
const duration<Rep2, Period2>& Right);
2)
template <class Clock, class Duration1, class Duration2>
constexpr bool operator<(
const time_point<Clock, Duration1>& Left,
const time_point<Clock, Duration2>& Right);
參數
Left
左邊的 duration 或 time_point 物件。
Right
右邊的 duration 或 time_point 物件。
傳回值
1) 如果 的刻度true數目小於 的Left刻度數目,則傳Right回 。 否則,此函式會傳回 false。
2) 如果在 true 之前傳LeftRight回 。 否則傳回 false。
operator<=
1) 轉換 duration的 比較其一般類型之後,判斷 的刻度 Left 數目是否小於或與 Right相同。
2) 判斷 自 的 Epoch Lefttime_point 以來的時間點是否小於或等於 中 time_point之 Epoch Right 之後的時間點。
1)
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr bool operator<=(
const duration<Rep1, Period1>& Left,
const duration<Rep2, Period2>& Right);
2)
template <class Clock, class Duration1, class Duration2>
constexpr bool operator<=(
const time_point<Clock, Duration1>& Left,
const time_point<Clock, Duration2>& Right);
參數
Left
左邊的 duration 或 time_point 物件。
Right
右邊的 duration 或 time_point 物件。
傳回值
1) 如果 的true刻度數目小於或等於 的Left刻度數目,則傳Right回 。 否則,此函式會傳回 false。
2) 如果true之前或 等於 ,Left則傳Right回 。 否則傳回 false。
operator==
判斷是否:
1) duration 物件代表具有相同長度的時間間隔。
2) time_point 物件代表相同的時間點。
3) day 物件代表同一天。
4) month 物件代表同一個月。
5) month_day 物件代表相同的月和日。
6) month_day_last 物件代表同一個月。
7) month_weekday 物件代表同一個月和第 n 個工作日。
8) month_weekday_last 物件代表同一個月和最後一個工作日。
9) weekday 物件代表相同的工作日。
10) weekday_last 物件代表當月的最後一個工作日。
11) weekday_indexed 代表相同的工作日索引。
12) year 代表同一年。
13) year_month 代表同一年和月份。
14) year_month_day 代表同一年、月和日。
15) year_month_day_last 代表年份和月份的同一天。
16) year_month_weekday 代表相同的工作日、年份和月份。
17) year_month_weekday_last 代表當月、年和月的最後一個工作日相同。
18) time_zone_link 具有相同的 name。 不會考慮名稱 target 。
19) zoned_time 代表相同的時間和時區。
// 1) duration<Rep, Period>
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr bool operator==(
const duration<Rep1, Period1>& Left,
const duration<Rep2, Period2>& Right);
// 2) time_point
template <class Clock, class Duration1, class Duration2>
constexpr bool operator==(
const time_point<Clock, Duration1>& Left,
const time_point<Clock, Duration2>& Right);
// 3) day
constexpr bool operator==(const day& Left, const day& Right) noexcept; // C++20
// 4) month
constexpr bool operator==(const month& Left, const month& Right) noexcept; // C++20
// 5) month_day
constexpr bool operator==(const month_day& Left, const month_day& Right) noexcept; // C++20
// 6) month_day_last
constexpr bool operator==(const month_day_last& Left, const month_day_last& Right) noexcept; // C++20
// 7) month_weekday
constexpr bool operator==(const month_weekday& Left, const month_weekday& Right) noexcept; // C++20
// 8) month_weekday_last
constexpr bool operator==(const month_weekday_last& Left, const month_weekday_last& Right) noexcept; // C++20
// 9) weekday
constexpr bool operator==(const weekday& Left, const weekday& Right) noexcept; // C++20
// 10) weekday_last
constexpr bool operator==(const weekday_last& Left, const weekday_last& Right) noexcept; // C++20
// 11) weekday_indexed
constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept; // C++20
// 12) year
constexpr bool operator==(const year& Left, const year& y ) noexcept; // C++20
// 13) year_month
constexpr bool operator==(const year_month& Left, const year_month& Right) noexcept; // C++20
// 14) year_month_day
constexpr bool operator==(const year_month_day& Left, const year_month_day& Right) noexcept; // C++20
// 15) year_month_day_last
constexpr bool operator==(const year_month_day_last& Left, const year_month_day_last& Right) noexcept; // C++20
// 16) year_month_weekday
constexpr bool operator==(const year_month_weekday& Left, const year_month_weekday& Right) noexcept; // C++20
// 17) year_month_weekday_last
constexpr bool operator==(const year_month_weekday_last& Left, const year_month_weekday_last& Right) noexcept; // C++20
// 18) time_zone_link
bool operator==(const time_zone_link& Left, const time_zone_link& Right) noexcept; // C++20
// 19) zoned_time
template <class Duration1, class Duration2, class TimeZonePtr>
bool operator==(const zoned_time<Duration1, TimeZonePtr>& Left, const zoned_time<Duration2, TimeZonePtr>& Right); // C++20
參數
Left
要比較的左物件,例如 Left == Right
Right
要比較的右側物件。
傳回值
1) 如果和 trueLeft 的型別的刻度數目相等,則傳Right回 。 否則傳回 false。
2) 如果與 true 代表相同的時間點,則傳LeftRight回 。 否則傳回 false。
3-17) 如果 true 與 Left 具有相同值,則傳回 Right 。 否則傳回 false。
18) 如果 true傳回 Left.name() == Right.name() 。 否則傳回 false。
19) 如果trueLeft.get_time_zone() == Right.get_time_zone() && Left.get_sys_time() == Right.get_sys_time();
operator>
1) 轉換 duration的 比較其一般型別之後,判斷 的刻度 Left 數目是否大於 Right。
2) 判斷 自 的 Epoch Lefttime_point 之後的時間點是否大於 中 time_point之 Epoch 之後的時間Right點。
1)
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr bool operator>(
const duration<Rep1, Period1>& Left,
const duration<Rep2, Period2>& Right);
2)
template <class Clock, class Duration1, class Duration2>
constexpr bool operator>(
const time_point<Clock, Duration1>& Left,
const time_point<Clock, Duration2>& Right);
參數
Left
左邊的 duration 或 time_point 物件。
Right
右邊的 duration 或 time_point 物件。
傳回值
1) 如果 的true刻度數目大於 的Left刻度數目,則傳Right回 。 否則,此函式會傳回 false。
2) 如果true之後Left傳回 Right 。 否則傳回 false。
operator>=
1) 轉換 duration的 比較其一般類型之後,判斷 的刻度 Left 數目是否大於或等於 Right。
2) 判斷 自 的 Epoch Lefttime_point 以來的時間點是否大於或等於 中 time_point之 Epoch Right 之後的時間點。
1)
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr bool operator>=(
const duration<Rep1, Period1>& Left,
const duration<Rep2, Period2>& Right);
2)
template <class Clock, class Duration1, class Duration2>
constexpr bool operator>=(
const time_point<Clock, Duration1>& Left,
const time_point<Clock, Duration2>& Right);
參數
Left
左邊的 duration 或 time_point 物件。
Right
右邊的 duration 或 time_point 物件。
傳回值
1) 如果 的true刻度數目大於或等於 的Left刻度數目,則傳Right回 。 否則,此函式會傳回 false。
2) 如果true之後傳回 Left ,或 等於 Right。 否則傳回 false。
operator<=>
宇宙飛船運算符,使用 operator==來合成 、、<<=、 >和 >= 的運算符!=,適用於下列類型:
daydurationmonthmonth_daymonth_day_lasttime_pointtime_zone_linkyearyear_monthyear_month_day_last
1)
constexpr bool operator<=>(const day& Left, const day& Right) noexcept; // C++20
constexpr std::strong_ordering operator<=>(const month& Left, const month& Right) noexcept; // C++20
constexpr strong_ordering operator<=>(const month_day& Left, const month_day& Right) noexcept; // C++20
constexpr std::strong_ordering operator<=>(const year& Left, const year& Right ) noexcept; // C++20
constexpr strong_ordering operator<=>(const year_month& Left, const year_month& Right) noexcept; // C++20
template<class Clock, class Duration1, three_way_comparable_with<Duration1> Duration2>
constexpr auto operator<=>(const time_point<Clock, Duration1>& Left, const time_point<Clock, Duration2>& Right); // C++20
template<class Rep1, class Period1, class Rep2, class Period2>
requires three_way_comparable<typename CT::rep>
constexpr auto operator<=>(const duration<Rep1, Period1>& Left, const duration<Rep2, Period2>& Right);
2)
constexpr strong_ordering operator<=>(const month_day_last& Left, const month_day_last& Right) noexcept;
3)
constexpr strong_ordering operator<=>(const year_month_day_last& Left, const year_month_day_last& Right) noexcept;
4)
strong_ordering operator<=>(const time_zone_link& Left, const time_zone_link& Right) noexcept;
參數
Left、Right
要比較的day、duration、monthmonth_daymonth_day_lasttime_pointtime_zone_linkyear、year_month、year_month_day、 。 year_month_day_last
傳回值
1)
0 如果 Left == Right
< 0 如果 Left < Right
> 0 如果 Left > Right
2)
相當於: Left.month() <=> Right.month()
3)
相當於:
if (auto c = Left.year() <=> Right.year(); c != 0) return c;
return Left.month_day_last() <=> Right.month_day_last();
4)
相當於:
Left.name() <=> Right.name()
範例: operator<=>
// compile using: /std:c++latest
#include <iostream>
#include <chrono>
using namespace std::chrono; // for day and 'd' literals
int main()
{
day d1{3};
day d2{2};
if ((d1 <=> d2) == 0)
{
std::cout << "equal\n";
}
else if ((d1 <=> d2) < 0)
{
std::cout << "d1 < d2\n";
}
else if ((d1 <=> d2) > 0)
{
std::cout << "d1 > d2\n";
}
std::cout << std::boolalpha << (1d <= 1d) << ' ' << (1d != 2d) << ' ' << (2d > 3d);
return 0;
}
d1 > d2
true true false
operator<<
將下列類型輸出至資料串流:
dayfile_timegps_timehh_mm_sslocal_timelocal_infomonthmonth_daymonth_day_lastmonth_weekdaymonth_weekday_lastsys_infotai_timeutc_timeweekdayweekday_indexedweekday_lastyearyear_monthyear_month_dayyear_month_day_lastyear_month_weekdayyear_month_weekday_lastzoned_time
// 1) day
template <class CharT, class Traits>
std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os, const day& d); // C++20
// 2) hh_mm_ss
template<class CharT, class traits, class Duration>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const hh_mm_ss<Duration>& hms); // C++20
// 3) month
template<class CharT, class Traits>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const month& m); // C++20
// 4) month_day
template<class CharT, class Traits>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const month_day& md); // C++20
// 5) month_day_last
template<class CharT, class Traits>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const month_day_last& mdl); // C++20
// 6) month_weekday
template<class CharT, class Traits>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const month_weekday& mwd); // C++20
// 7) month_weekday_last
template<class CharT, class Traits>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const month_weekday_last& mwdl); // C++20
// 8) weekday
template<class CharT, class Traits>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const weekday& wd); // C++20
// 9) weekday_indexed
template<class CharT, class Traits>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const weekday_indexed& wdi); // C++20
// 10) weekday_last
template<class CharT, class Traits>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const weekday_last& wdl); // C++20
// 11) year
template <class CharT, class Traits>
std::basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const year& y); // C++20
// 12) year_month
template<class CharT, class Traits>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const year_month& ym); // C++20
// 13) year_month_day
template<class CharT, class Traits>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const year_month_day& ymd); // C++20
// 14) year_month_day_last
template<class CharT, class Traits>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const year_month_day_last& ymdl); // C++20
// 15) year_month_weekday
template<class CharT, class Traits>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const year_month_weekday& ymwd); // C++20
// 16) year_month_weekday_last
template<class CharT, class Traits>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const year_month_weekday_last& ymwdl); // C++20
// 17) tai_time
template<class CharT, class Traits, class Duration>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const tai_time<Duration>& t); // C++20
// 18) utc_time
template<class CharT, class Traits, class Duration>
basic_ostream<CharT, traits>&
operator<<(basic_ostream<CharT, Traits>& os, const utc_time<Duration>& t); // C++20
// 19) gps_time
template<class CharT, class Traits, class Duration>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const gps_time<Duration>& t); // C++20
// 20) local_time
template<class CharT, class Traits, class Duration>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const local_time<Duration>& t); // C++20
// 21) sys_info
template<class CharT, class Traits>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const sys_info& si);
// 22) local_info
template<class CharT, class Traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<CharT, Traits>& os, const local_info& li);
// 23) zoned_time
template<class CharT, class Traits, class Duration, class TimeZonePtr>
basic_ostream<CharT, Traits>&
operator<<(basic_ostream<CharT, Traits>& os, const zoned_time<Duration, TimeZonePtr>& zt);
參數
CharT
要從數據流讀取並儲存在字串中的單一字元數據類型。 C++標準連結庫提供這個類別範本的特製化,以及類型、 和 的元素類型 stringcharwstringwchar_tu16string定義。char16_tu32stringchar32_t
Traits
描述 CharT 和 basic_string 特製化的屬性basic_istream。
os
要發出 day 值的輸出數據流。
d
要 day 輸出的 。
hms
要 hh_mm_ss 輸出的 。
li
要 local_info 輸出的 。
m
要 month 輸出的 。
md
要 month_day 輸出的 。
mdl
要 month_day_last 輸出的 。
mwd
要 month_weekday 輸出的 。
mwdl
要 month_weekday_last 輸出的 。
si
要 sys_info 輸出的 。
t
local_time、gps_time、 tai_time或 utc_time 輸出。
wd
要 weekday 輸出的 。
wdi
要 weekday_indexed 輸出的 。
wdl
要 weekday_last 輸出的 。
y
要 year 輸出的 。
ym
要 year_month 輸出的 。
ymd
要 year_month_day 輸出的 。
ymdl
要 year_month_day_last 輸出的 。
ymwd
要 year_month_weekday 輸出的 。
ymwdl
要 year_month_weekday_last 輸出的 。
zt
要 zoned_time 輸出的 。
傳回值
您傳入的輸出數據流, os
備註
1) 值 day 會輸出為十進位數,如果結果為單一數位,則為前置零。 如果 !d.ok()為 ,則 「不是有效的日期」會附加至輸出。
2) 值 hh_mm_ss 會輸出為小時:分:秒:千秒。 例如, "00:00:05.721”
3) 使用與 os相關聯地區設定的縮寫月份名稱是輸出。 例如: Jan 。 如果 !m.ok()為 ,則會 " is not a valid month" 附加至輸出。
4) 縮寫月份名稱,使用與 相關聯的 os地區設定,後面接著日期,如果結果為單一數位,則為前置零。 例如: Jan/05 。 如果 !md.ok()為 ,則 " is not a valid month" 可能會附加至月份的輸出,而且 "is not a valid day" 可能會附加至當天的輸出。 例如: 204 is not a valid month/204 is not a valid day 。
5) 縮寫月份名稱,使用與 相關聯的 os地區設定,後面接著 /last。 例如: Jan/last 。
6) 縮寫的工作日名稱,使用與 相關聯的 os地區設定,後面接著它以方括號表示的月份的第 n 個工作日。 例如: Mon[1] 。
7) 縮寫的工作日名稱,使用與 相關聯的 os地區設定,後面接著它以方括號表示的月份的最後一個工作日。 例如: Jan/Mon[last] 。
8) 使用與 os相關聯地區設定的縮寫工作日名稱是輸出。 如果 !wd.ok()為 ,則會 " is not a valid weekday" 附加至輸出。
9) 使用與 相關聯 os地區設定的縮寫工作日名稱是輸出,後面接著以方括弧括住月份的工作日。 例如: Mon[3] 。 如果 !wd.ok()為 ,則 " is not a valid weekday" 可能會附加至星期的輸出日,而且 "is not a valid index" 可能會附加至工作日索引輸出。
10) 使用 與 os相關聯的地區設定,一個月的最後一個工作日是輸出,後面接著 ,後面接著 [last]日期。 例如: Tue[last] 2019-10-29 。 如果 !wd.ok()為 ,則 " is not a valid weekday" 可能會附加至星期的輸出日,而且 "is not a valid index" 可能會附加至工作日索引輸出。
11) 如果結果小於,則年份會以 0(零)到四位數填補。 如果 !y.ok()為 ,則會 " is not a valid year" 附加至輸出。
12) 是 year_month 格式為 yyy-mm-dd 的輸出。 如果 ym.ok 傳 false回 ,則會 " is not a valid date" 附加 。
13) 是 year_month_day 格式為 yyyy-mm-dd 的輸出。 如果 ymd.ok 傳 false回 ,則會 " is not a valid date" 附加 。
14) 的 year_month_day_last 輸出格式為yyyy/month/last。 例如: 2020/May/last 。
15) 是 year_month_weekday 格式為 yyyy/month/weekday[index] 的輸出。 例如,1996/Jan/Wed[1]
16) 是 year_month_weekday_last yyyy/month/weekday[last] 格式的輸出。 例如,1996/Jan/Wed[last]
17) 是 tai_time 格式為 yyyy-mm-dd hh:mm:ss.sss 的輸出。 例如,2021-08-13 23:23:08.4358666
18) 是 utc_time yyyy-mm-dd hh:mm:ss.ss 格式的輸出。 例如,2021-08-13 23:23:08.4358666
19) 是 gps_time 格式為 yyyy-mm-dd hh:mm:ss.ss 的輸出。 例如,2021-08-13 23:23:08.4358666
20) 輸出 local_time 為時鐘 epoch 之後的秒數。 其輸出就像 由 os << std::chrono::sys_time<Duration>(some_local_time.time_since_epoch());一樣。 例如,如果 some_local_time 是 2021 年 8 月 18 日下午 3:13,則輸出為 1597792380。
21) 在 Microsoft 的實作中,會sys_info輸出為 、beginend、offset、 save和 abbrev 欄位。 例如:begin: 2021-03-14 10:00:00, end: 2021-11-07 09:00:00, offset: -25200s, save: 60min, abbrev: PDT
22) 在Microsoft的實作中,a local_info 輸出為 yyyy-mm-dd hh:mm:ss.ssssss。 例如,2021-09-17 13:55:59.6590120
23) 中的當地時間 zoned_time 是 zt.get_local_time()使用yyyy-mm-dd hh:mm:ss時區格式輸出。 例如,2021-09-15 10:45:00 GMT-6
範例: operator<<
// compile using: /std:c++latest
#include <iostream>
#include <chrono>
using namespace std::chrono;
int main()
{
std::cout << utc_clock::now() << '\n';
year_month ym{ 2021y / April };
std::cout << ym;
return 0;
}
2021-08-16 20:47:05.6299822
2021/Apr
operator modulo
上模數運算的 duration運算符。
1)
template <class Rep1, class Period1, class Rep2>
constexpr duration<Rep1, Period1, Rep2>::type
operator%(
const duration<Rep1, Period1>& Dur,
const Rep2& Div);
2)
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
operator%(
const duration<Rep1, Period1>& Left,
const duration<Rep2, Period2>& Right);
參數
Dur
duration 物件。
Div
整數值。
Left
被除數。 模數是除數后的餘數。
Right
右 duration 物件,除數。
傳回值
1) 傳回 duration 間隔長度為 Dur 模數 Div的物件。
2) 傳回代表 Left 模數 Right的值。
operator/ 的 duration
duration 物件的除法運算子。
1)
template <class Rep1, class Period1, class Rep2>
constexpr duration<typename common_type<Rep1, Rep2>::type, Period1>
operator/(
const duration<Rep1, Period1>& Dur,
const Rep2& Div);
2)
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr typename common_type<Rep1, Rep2>::type
operator/(
const duration<Rep1, Period1>& Left,
const duration<Rep2, Period2>& Right);
參數
Dur
duration 物件。
Div
整數值。
Left
左側 duration 物件。
Right
右 duration 物件。
傳回值
1) duration 物件,其間隔長度是 除以 值 Dur的長度Div。
2) 和 Left的間隔長度Right比率。
除非 is_convertible<Rep2, common_type<Rep1, Rep2>>保留 true,而且 Rep2 不是的 duration具現化,否則第一個運算符不會參與多載解析。 如需詳細資訊,請參閱 <type_traits>。
operator/行事曆日期
提供語法,以下列形式建立行事曆日期:
month/day/year
day/month/year
year/month/day
您可以將日期取代為:
last
weekday[n] 當月第 n 天
weekday[last] 當月的最後 weekday 一個。
部份日期的格式如下:
year_month ym = 2015y/April;
month_day md1 = April/4;
month_day md2 = 4d/April;
只要解譯不模棱兩可,就可以使用整數。
///////// returns year_month
// 1
constexpr year_month
operator/(const year& y, const month& m) noexcept; // C++20
// 2
constexpr year_month
operator/(const year& y, int m) noexcept; // C++20
///////// returns month_day
// 3
constexpr month_day
operator/(const month& m, const day& d) noexcept; // C++20
// 4
constexpr month_day
operator/(const month& m, int d) noexcept; // C++20
// 5
constexpr month_day
operator/(int m, const day& d) noexcept; // C++20
// 6
constexpr month_day
operator/(const day& d, const month& m) noexcept; // C++20
// 7
constexpr month_day
operator/(const day& d, int m) noexcept; // C++20
///////// returns month_day_last
// 8
constexpr month_day_last
operator/(const month& m, last_spec) noexcept; // C++20
// 9
constexpr month_day_last
operator/(int m, last_spec) noexcept; // C++20
// 10
constexpr month_day_last
operator/(last_spec, const month& m) noexcept; // C++20
// 11
constexpr month_day_last
operator/(last_spec, int m) noexcept; // C++20
///////// returns month_weekday
// 12
constexpr month_weekday
operator/(const month& m, const weekday_indexed& wdi) noexcept; // C++20
// 13
constexpr month_weekday
operator/(int m, const weekday_indexed& wdi) noexcept; // C++20
// 14
constexpr month_weekday
operator/(const weekday_indexed& wdi, const month& m) noexcept; // C++20
// 15
constexpr month_weekday
operator/(const weekday_indexed& wdi, int m) noexcept; // C++20
///////// returns month_weekday_last
// 16
constexpr month_weekday_last
operator/(const month& m, const weekday_last& wdl) noexcept; // C++20
// 17
constexpr month_weekday_last
operator/(int m, const weekday_last& wdl) noexcept; // C++20
// 18
constexpr month_weekday_last
operator/(const weekday_last& wdl, const month& m) noexcept; // C++20
// 19
constexpr month_weekday_last
operator/(const weekday_last& wdl, int m) noexcept; // C++20
///////// returns year_month_day
// 20
constexpr year_month_day
operator/(const year_month& ym, const day& d) noexcept; // C++20
// 21
constexpr year_month_day
operator/(const year_month& ym, int d) noexcept; // C++20
// 22
constexpr year_month_day
operator/(const year& y, const month_day& md) noexcept; // C++20
// 23
constexpr year_month_day
operator/(int y, const month_day& md) noexcept; // C++20
// 24
constexpr year_month_day
operator/(const month_day& md, const year& y) noexcept; // C++20
// 25
constexpr year_month_day
operator/(const month_day& md, int y) noexcept; // C++20
///////// returns year_month_day_last
// 26
constexpr year_month_day_last
operator/(const year_month& ym, last_spec) noexcept; // C++20
// 27
constexpr year_month_day_last
operator/(const year& y, const month_day_last& mdl) noexcept; // C++20
// 28
constexpr year_month_day_last
operator/(int y, const month_day_last& mdl) noexcept; // C++20
// 29
constexpr year_month_day_last
operator/(const month_day_last& mdl, const year& y) noexcept; // C++20
// 30
constexpr year_month_day_last
operator/(const month_day_last& mdl, int y) noexcept; // C++20
///////// returns year_month_weekday
// 31
constexpr year_month_weekday
operator/(const year_month& ym, const weekday_indexed& wdi) noexcept; // C++20
// 32
constexpr year_month_weekday
operator/(const year& y, const month_weekday& mwd) noexcept; // C++20
// 33
constexpr year_month_weekday
operator/(int y, const month_weekday& mwd) noexcept; // C++20
// 34
constexpr year_month_weekday
operator/(const month_weekday& mwd, const year& y) noexcept; // C++20
// 35
constexpr year_month_weekday
operator/(const month_weekday& mwd, int y) noexcept; // C++20
///////// returns year_month_weekday_last
// 36
constexpr year_month_weekday_last
operator/(const year_month& ym, const weekday_last& wdl) noexcept; // C++20
// 37
constexpr year_month_weekday_last
operator/(const year& y, const month_weekday_last& mwdl) noexcept; // C++20
// 38
constexpr year_month_weekday_last
operator/(int y, const month_weekday_last& mwdl) noexcept; // C++20
// 39
constexpr year_month_weekday_last
operator/(const month_weekday_last& mwdl, const year& y) noexcept; // C++20
// 40
constexpr year_month_weekday_last
operator/(const month_weekday_last& mwdl, int y) noexcept; // C++20
參數
d
當天。 提供為範圍[1,31] 中的整數,或以 提供為 day。
lastspec
空白標籤類型,表示序列中的最後一個項目。 例如, 2021y/May/last 是 2021 年 5 月的最後一天。
m
月份。 提供為範圍 [1,12] 或 中的 month整數。
md
月和日。
mdl
指定月份的最後一天。
mwd
指定月份的第 n 個工作日。
mwdl
指定月份的最後一個工作日。
wdi
工作日索引 (weekday_indexed)。 例如, weekday_indexed(Monday, 1) 是一個月中的第一個星期一。
wdl
一個月的最後一個工作日。 例如, Monday[last] 是一個月的最後一個星期一。
y
年。 提供為整數,或提供為 year。
ym
年份和月份。
傳回值
1) year_month(y, m)
2) year_month(y, month(m))
3) month_day(m, d)
4) month_day(m, day(d))
5) month_day(month(m), d)
6) month_day(m, d)
7) month_day(month(m), d)
8) month_day_last(m)
9) month_day_last(month(m))
10) month_day_last(m)
11) month_day_last(month(m))
12) month_weekday(m, wdi)
13) month_weekday(month(m), wdi)
14) month_weekday(m, wdi)
15) month_weekday(month(m), wdi)
16) month_weekday_last(m, wdl)
17) month_weekday_last(month(m), wdl)
18) month_weekday_last(m, wdl)
19) month_weekday_last(month(m), wdl)
20) year_month_day(ym.year(), ym.month(), d)
21) year_month_day(ym.year(), ym.month(), day(d))
22) year_month_day(y, md.month(), md.day())
23) year_month_day(year(y), md.month(), md.day())
24) year_month_day(y, md.month(), md.day())
25) year_month_day(year(y), md.month(), md.day())
26) year_month_day_last(ym.year(), month_day_last(ym.month()))
27) year_month_day_last(y, mdl)
28) year_month_day_last(year(y), mdl)
29) year_month_day_last(y, mdl)
30) year_month_day_last(year(y), mdl)
31) year_month_weekday(ym.year(), ym.month(), wdi)
32) year_month_weekday(y, mwd.month(), mwd.weekday_indexed())
33) year_month_weekday(year(y), mwd.month(), mwd.weekday_indexed())
34) year_month_weekday(y, mwd.month(), mwd.weekday_indexed())
35) year_month_weekday(year(y), mwd.month(), mwd.weekday_indexed())
36) year_month_weekday_last(ym.year(), ym.month(), wdl)
37) year_month_weekday_last(y, mwdl.month(), mwdl.weekday_last())
38) year_month_weekday_last(year(y), mwdl.month(), mwdl.weekday_last())
39) year_month_weekday_last(y, mwdl.month(), mwdl.weekday_last())
40) year_month_weekday_last(year(y), mwdl.month(), mwdl.weekday_last())
範例: operator/ 行事曆日期
// compile using: /std:c++latest
#include <iostream>
#include <chrono>
using namespace std::chrono;
int main()
{
month m{ July }; // Jul
month_day md{ April / 4 }; // Apr/04
month_day md2{ 4d / April }; // Apr/04
month_day_last mdl{ January / last }; // Jan/last
month_weekday mw{ 11 / Monday[1] }; // Nov/Mon[1]
month_weekday_last mwl{ January / Monday[last] }; // Jan/Mon[last]
weekday wd{ Monday }; // Mon
weekday_indexed wdi{ Monday, 1 }; // Mon[1]
year_month ym{ 2021y / April }; // 2021/Apr
year_month_day ymd{ January / 1d / 2021y }; // 2021-01-01
year_month_day ymd2{ 2021y / 5 / 7 }; // 2021-05-07
year_month_day_last ymdl{ April / last / 1975 }; // 1975/Apr/last
year_month_weekday ymw{ 1997y / January / Wednesday[1] }; // 1997/Jan/Wed[1]
year_month_weekday_last ymwl{ 1997y / January / Wednesday[last] }; // 1997/Jan/Wed[last]
int yearValue{ 2021 / 4 / 4 }; // 126
std::cout << m << '\n' << md << '\n' << md2 << '\n' << mdl << '\n' << mw
<< '\n' << mwl << '\n' << wd << '\n' << wdi << '\n'
<< ym << '\n' << ymd << '\n' << ymd2 << '\n' << ymdl
<< '\n' << ymw << '\n' << ymwl << '\n' << yearValue;
return 0;
}
Jul
Apr/04
Apr/04
Jan/last
Nov/Mon[1]
Jan/Mon[last]
Mon
Mon[1]
2021/Apr
2021-01-01
2021-05-07
1975/Apr/last
1997/Jan/Wed[1]
1997/Jan/Wed[last]
126