|
1 | 1 | ---
|
2 | 2 | description: "Learn more about: <chrono> operators"
|
3 | 3 | title: "<chrono> operators"
|
4 |
| -ms.date: "6/30/2021" |
5 |
| -f1_keywords: ["chrono/std::operator modulo", "chrono/std::operator+", "chrono/std::chrono::day::operator+", "chrono/std::chrono::duration::operator+", "chrono/std::chrono::month::operator+", "chrono/std::chrono::time_point::operator+", "chrono/std::chrono::weekday::operator+", "chrono/std::chrono::year_month::operator+", "chrono/std::chrono::year::operator+", "chrono/std::chrono::year_month_day::operator+", "chrono/std::chrono::year_month_day_last::operator+", "chrono/std::chrono::year_month_weekday::operator+", "chrono/std::chrono::year_month_weekday_last::operator+", "chrono/std::operator!=", "chrono/std::operator*", "chrono/std::operator/", "chrono/std::operator-", "chrono/std::operator<", "chrono/std::operator<=", "chrono/std::operator<", "chrono/std::operator==", "chrono/std::operator>>", "chrono/std::operator<=>", "chrono/std::chrono::day::operator<=>", "chrono/std::chrono::month::operator<=>", "chrono/std::chrono::year::operator<=>", "chrono/std::chrono::year_month::operator<=>", "chrono/std::chrono::time_point::operator<=>", "chrono/std::chrono::duration::operator<=>", "chrono/std::chrono::month_day_last::operator<=>", "chrono/std::chrono::year_month_day_last::operator<=>", "chrono/std::operator==", "chrono/std::chrono::year::operator<==>", "chrono/std::chrono::day::operator==", "chrono/std::chrono::duration::operator==", "chrono/std::chrono::month::operator==", "chrono/std::chrono::month_day::operator==", "chrono/std::chrono::month_day_last::operator==", "chrono/std::chrono::month_weekday::operator==", "chrono/std::chrono::month_weekday_last::operator==", "chrono/std::chrono::time_point::operator==", "chrono/std::chrono::weekday::operator==", "chrono/std::chrono::year_month::operator==", "chrono/std::chrono::year::operator==", "chrono/std::chrono::year_month_day::operator==", "chrono/std::chrono::year_month_day_last::operator==", "chrono/std::chrono::year_month_weekday_last::operator==", "chrono/std::chrono::year_month_weekday::operator==", "chrono/std::chrono::month_weekday_last::operator==", "chrono/std::chrono::weekday::operator==", "chrono/std::chrono::weekday_last::operator==", "chrono/std::chrono::year_month_weekday_indexed::operator==", "chrono/std::chrono::year_month_weekday_last::operator==", "chrono/std::chrono::year::operator==", "chrono/std::chrono::year_month::operator==", "chrono/std::chrono::year_month_day::operator==", "chrono/std::chrono::year_month_day_last::operator==", "chrono/std::operator-", "chrono/std::chrono::day::operator-", "chrono/std::chrono::duration::operator-", "chrono/std::chrono::month::operator-", "chrono/std::chrono::time_point::operator-", "chrono/std::chrono::weekday::operator-", "chrono/std::chrono::year_month::operator-", "chrono/std::chrono::year::operator-", "chrono/std::chrono::year_month_day::operator-", "chrono/std::chrono::year_month_day_last::operator-", "chrono/std::chrono::year_month_weekday::operator-", "chrono/std::chrono::year_month_weekday_last::operator-", "chrono/std::chrono::day::operator<<", "chrono/std::chrono::hh_mm_ss::operator<<", "chrono/std::chrono::month_day::operator<<", "chrono/std::chrono::month_day_last::operator<<", "chrono/std::chrono::month_weekday::operator<<", "chrono/std::chrono::month_weekday_last::operator<<", "chrono/std::chrono::weekday::operator<<", "chrono/std::chrono::weekday_indexed::operator<<", "chrono/std::chrono::weekday_last::operator<<", "chrono/std::chrono::year::operator<<", "chrono/std::chrono::year_month_day::operator<<", "chrono/std::chrono::year_month_day_last::operator<<", "chrono/std::chrono::year_month_weekday::operator<<"] |
| 4 | +ms.date: "08/13/2021" |
| 5 | +f1_keywords: ["chrono/std::operator modulo", "chrono/std::operator+", "chrono/std::chrono::day::operator+", "chrono/std::chrono::duration::operator+", "chrono/std::chrono::month::operator+", "chrono/std::chrono::time_point::operator+", "chrono/std::chrono::weekday::operator+", "chrono/std::chrono::year_month::operator+", "chrono/std::chrono::year::operator+", "chrono/std::chrono::year_month_day::operator+", "chrono/std::chrono::year_month_day_last::operator+", "chrono/std::chrono::year_month_weekday::operator+", "chrono/std::chrono::year_month_weekday_last::operator+", "chrono/std::operator!=", "chrono/std::operator*", "chrono/std::operator/", "chrono/std::operator-", "chrono/std::operator<", "chrono/std::operator<=", "chrono/std::operator<", "chrono/std::operator==", "chrono/std::operator>>", "chrono/std::operator<=>", "chrono/std::chrono::day::operator<=>", "chrono/std::chrono::month::operator<=>", "chrono/std::chrono::year::operator<=>", "chrono/std::chrono::year_month::operator<=>", "chrono/std::chrono::time_point::operator<=>", "chrono/std::chrono::duration::operator<=>", "chrono/std::chrono::month_day_last::operator<=>", "chrono/std::chrono::year_month_day_last::operator<=>", "chrono/std::operator==", "chrono/std::chrono::year::operator<==>", "chrono/std::chrono::day::operator==", "chrono/std::chrono::duration::operator==", "chrono/std::chrono::month::operator==", "chrono/std::chrono::month_day::operator==", "chrono/std::chrono::month_day_last::operator==", "chrono/std::chrono::month_weekday::operator==", "chrono/std::chrono::month_weekday_last::operator==", "chrono/std::chrono::time_point::operator==", "chrono/std::chrono::weekday::operator==", "chrono/std::chrono::year_month::operator==", "chrono/std::chrono::year::operator==", "chrono/std::chrono::year_month_day::operator==", "chrono/std::chrono::year_month_day_last::operator==", "chrono/std::chrono::year_month_weekday_last::operator==", "chrono/std::chrono::year_month_weekday::operator==", "chrono/std::chrono::month_weekday_last::operator==", "chrono/std::chrono::weekday::operator==", "chrono/std::chrono::weekday_last::operator==", "chrono/std::chrono::year_month_weekday_indexed::operator==", "chrono/std::chrono::year_month_weekday_last::operator==", "chrono/std::chrono::year::operator==", "chrono/std::chrono::year_month::operator==", "chrono/std::chrono::year_month_day::operator==", "chrono/std::chrono::year_month_day_last::operator==", "chrono/std::operator-", "chrono/std::chrono::day::operator-", "chrono/std::chrono::duration::operator-", "chrono/std::chrono::month::operator-", "chrono/std::chrono::time_point::operator-", "chrono/std::chrono::weekday::operator-", "chrono/std::chrono::year_month::operator-", "chrono/std::chrono::year::operator-", "chrono/std::chrono::year_month_day::operator-", "chrono/std::chrono::year_month_day_last::operator-", "chrono/std::chrono::year_month_weekday::operator-", "chrono/std::chrono::year_month_weekday_last::operator-", "chrono/std::chrono::day::operator<<", "chrono/std::chrono::hh_mm_ss::operator<<", "chrono/std::chrono::month_day::operator<<", "chrono/std::chrono::month_day_last::operator<<", "chrono/std::chrono::month_weekday::operator<<", "chrono/std::chrono::month_weekday_last::operator<<", "chrono/std::chrono::weekday::operator<<", "chrono/std::chrono::weekday_indexed::operator<<", "chrono/std::chrono::weekday_last::operator<<", "chrono/std::chrono::year::operator<<", "chrono/std::chrono::year_month_day::operator<<", "chrono/std::chrono::year_month_day_last::operator<<", "chrono/std::chrono::year_month_weekday::operator<<", "chrono/std::chrono::utc_time::operator<<", "chrono/std::chrono::tai_time::operator<<", "chrono/std::chrono::gps_time::operator<<", "chrono/std::chrono::local_time::operator<<", "chrono/std::chrono::file_time::operator<<"] |
6 | 6 | ---
|
7 | 7 | # `<chrono>` operators
|
8 | 8 |
|
@@ -131,7 +131,7 @@ constexpr year_month_weekday_last operator+(const years& dy, const year_month_we
|
131 | 131 |
|
132 | 132 | 16\) Returns `(ymwdl.year() / ymwdl.month() + dm) / ymwdl.weekday_last()`. Note: The `/` used here is not a division operator but the date operator.
|
133 | 133 |
|
134 |
| -17\) Returns Returns: `ymwdl + dy` |
| 134 | +17\) Returns: `ymwdl + dy` |
135 | 135 |
|
136 | 136 | ### Example: `operator+`
|
137 | 137 |
|
@@ -804,12 +804,17 @@ true true false
|
804 | 804 | Output the following types to a stream:
|
805 | 805 |
|
806 | 806 | - [`day`](day-class.md)
|
| 807 | +- [`file_time`](chrono.md) |
| 808 | +- [`gps_time`](gps-clock-class.md) |
807 | 809 | - [`hh_mm_ss`](hhmmss-class.md)
|
| 810 | +- [`local_time`](local_t.md) |
808 | 811 | - [`month`](month-class.md)
|
809 | 812 | - [`month_day`](month-day-class.md)
|
810 | 813 | - [`month_day_last`](month-day-last-class.md)
|
811 | 814 | - [`month_weekday`](month-weekday-class.md)
|
812 | 815 | - [`month_weekday_last`](month-weekday-last-class.md)
|
| 816 | +- [`tai_time`](tai-clock-class.md) |
| 817 | +- [`utc_time`](utc-clock-class.md) |
813 | 818 | - [`weekday`](weekday-class.md)
|
814 | 819 | - [`weekday_indexed`](weekdayindexed-class.md)
|
815 | 820 | - [`weekday_last`](weekdaylast-class.md)
|
@@ -899,7 +904,27 @@ operator<<(basic_ostream<CharT, Traits>& os, const year_month_weekday& ymwd); //
|
899 | 904 | // 16) year_month_weekday_last
|
900 | 905 | template<class CharT, class Traits>
|
901 | 906 | basic_ostream<CharT, Traits>&
|
902 |
| -operator<<(basic_ostream<CharT, Traits>& os, const year_month_weekday_last& ymwdl); |
| 907 | +operator<<(basic_ostream<CharT, Traits>& os, const year_month_weekday_last& ymwdl); // C++ 20 |
| 908 | + |
| 909 | +// 17) tai_time |
| 910 | +template<class CharT, class Traits, class Duration> |
| 911 | +basic_ostream<CharT, Traits>& |
| 912 | +operator<<(basic_ostream<CharT, Traits>& os, const tai_time<Duration>& t); // C++ 20 |
| 913 | + |
| 914 | +// 18) utc_time |
| 915 | +template<class CharT, class Traits, class Duration> |
| 916 | +basic_ostream<CharT, traits>& |
| 917 | +operator<<(basic_ostream<CharT, Traits>& os, const utc_time<Duration>& t); // C++ 20 |
| 918 | + |
| 919 | +// 19) gps_time |
| 920 | +template<class CharT, class Traits, class Duration> |
| 921 | +basic_ostream<CharT, Traits>& |
| 922 | +operator<<(basic_ostream<CharT, Traits>& os, const gps_time<Duration>& t); // C++ 20 |
| 923 | + |
| 924 | +// 20) local_time |
| 925 | +template<class CharT, class Traits, class Duration> |
| 926 | +basic_ostream<CharT, Traits>& |
| 927 | +operator<<(basic_ostream<CharT, Traits>& os, const local_time<Duration>& t); // C++ 20 |
903 | 928 | ```
|
904 | 929 |
|
905 | 930 | ### Parameters
|
@@ -934,6 +959,9 @@ The `month_weekday` to output.
|
934 | 959 | *`mwdl`*\
|
935 | 960 | The `month_weekday_last` to output.
|
936 | 961 |
|
| 962 | +*`t`*\ |
| 963 | +The `local_time`, `gps_time`, `tai_time`, or `utc_time` to output. |
| 964 | +
|
937 | 965 | *`wd`*\
|
938 | 966 | The `weekday` to output.
|
939 | 967 |
|
@@ -969,7 +997,7 @@ The output stream you passed in, `os`
|
969 | 997 |
|
970 | 998 | 1\) The `day` value is output as a decimal number, with a leading zero if the result would be a single digit. If `!d.ok()`, then " isn't a valid day" is appended to the output.
|
971 | 999 |
|
972 |
| -2\) The `hh_mm_ss` value is output as hours:minutes:seconds:thousands of seconds. For example, `"00:00:05.721`" |
| 1000 | +2\) The `hh_mm_ss` value is output as hours:minutes:seconds:thousandths of seconds. For example, `"00:00:05.721`" |
973 | 1001 |
|
974 | 1002 | 3\) The abbreviated month name, using the locale associated with `os`, is output. For example, `Jan`. If `!m.ok()`, then `" is not a valid month"` is appended to the output.
|
975 | 1003 |
|
@@ -999,6 +1027,38 @@ The output stream you passed in, `os`
|
999 | 1027 |
|
1000 | 1028 | 16\) The `year_month_weekday_last` is output in the form yyyy/month/weekday[last]. For example, `1996/Jan/Wed[last]`
|
1001 | 1029 |
|
| 1030 | +17\) The `tai_time` is output in the form yyyy-mm-dd hh:mm:ss.sssssss. For example, `2021-08-13 23:23:08.4358666` |
| 1031 | +
|
| 1032 | +18\) The `utc_time` is output in the form yyyy-mm-dd hh:mm:ss.sssssss. For example, `2021-08-13 23:23:08.4358666` |
| 1033 | +
|
| 1034 | +19\) The `gps_time` is output in the form yyyy-mm-dd hh:mm:ss.sssssss. For example, `2021-08-13 23:23:08.4358666` |
| 1035 | +
|
| 1036 | +20\) The `local_time` is output as the number of seconds since the clock's epoch. It's output as though by `os << std::chrono::sys_time<Duration>(some_local_time.time_since_epoch());`. For example, if `some_local_time` is August 18, 2021 3:13pm, the output is `1597792380`. |
| 1037 | +
|
| 1038 | +### Example: `operator<<` |
| 1039 | +
|
| 1040 | +```cpp |
| 1041 | +// compile using: /std:c++latest |
| 1042 | +#include <iostream> |
| 1043 | +#include <chrono> |
| 1044 | +
|
| 1045 | +using namespace std::chrono; |
| 1046 | +
|
| 1047 | +int main() |
| 1048 | +{ |
| 1049 | + std::cout << utc_clock::now() << '\n'; |
| 1050 | +
|
| 1051 | + year_month ym{ 2021y / April }; |
| 1052 | + std::cout << ym; |
| 1053 | + return 0; |
| 1054 | +} |
| 1055 | +``` |
| 1056 | + |
| 1057 | +```output |
| 1058 | +2021-08-16 20:47:05.6299822 |
| 1059 | +2021/Apr |
| 1060 | +``` |
| 1061 | + |
1002 | 1062 | ## <a name="op_modulo"></a> `operator modulo`
|
1003 | 1063 |
|
1004 | 1064 | Operator for modulo operations on [`duration`](../standard-library/duration-class.md) objects.
|
|
0 commit comments