命名空间
变体
操作

std::chrono::operator/(calendar)

来自 cppreference.com
< cpp‎ | chrono
 
 
实用程序库
语言支持
类型支持 (基本类型,RTTI)
库功能测试宏 (C++20)
动态内存管理
程序实用程序
协程支持 (C++20)
可变参数函数
调试支持
(C++26)
三方比较
(C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
通用实用程序
日期和时间
函数对象
格式化库 (C++20)
(C++11)
关系运算符 (C++20 中已弃用)
整数比较函数
(C++20)(C++20)(C++20)   
(C++20)
交换类型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
通用词汇类型
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)
基本字符串转换
(C++17)
(C++17)

 
 
定义在头文件 <chrono>
year_month
constexpr auto operator/( const std::chrono::year& y,

                          const std::chrono::month& m ) noexcept

    -> std::chrono::year_month;
(1) (自 C++20)
constexpr auto operator/( const std::chrono::year& y, int m ) noexcept
    -> std::chrono::year_month;
(2) (自 C++20)
month_day
constexpr auto operator/( const std::chrono::month& m,

                          const std::chrono::day& d ) noexcept

    -> std::chrono::month_day;
(3) (自 C++20)
constexpr auto operator/( const std::chrono::month& m, int d ) noexcept
    -> std::chrono::month_day;
(4) (自 C++20)
constexpr auto operator/( int m, const std::chrono::day& d ) noexcept
    -> std::chrono::month_day;
(5) (自 C++20)
constexpr auto operator/( const std::chrono::day& d,

                          const std::chrono::month& m ) noexcept

   -> std::chrono::month_day;
(6) (自 C++20)
constexpr auto operator/( const std::chrono::day& d, int m ) noexcept
    -> std::chrono::month_day;
(7) (自 C++20)
month_day_last
constexpr auto operator/( const std::chrono::month& m,

                         std::chrono::last_spec ) noexcept

    -> std::chrono::month_day_last;
(8) (自 C++20)
constexpr auto operator/( int m, std::chrono::last_spec ) noexcept
    -> std::chrono::month_day_last;
(9) (自 C++20)
constexpr auto operator/( std::chrono::last_spec,

                          const std::chrono::month& m ) noexcept

    -> std::chrono::month_day_last;
(10) (自 C++20)
constexpr auto operator/( std::chrono::last_spec, int m ) noexcept
    -> std::chrono::month_day_last;
(11) (自 C++20)
month_weekday
constexpr auto operator/( const std::chrono::month& m,

                          const std::chrono::weekday_indexed& wdi ) noexcept

    -> std::chrono::month_weekday;
(12) (自 C++20)
constexpr auto operator/( int m, const std::chrono::weekday_indexed& wdi ) noexcept
    -> std::chrono::month_weekday;
(13) (自 C++20)
constexpr auto operator/( const std::chrono::weekday_indexed& wdi,

                          const std::chrono::month& m ) noexcept

    -> std::chrono::month_weekday;
(14) (自 C++20)
constexpr auto operator/( const std::chrono::weekday_indexed& wdi, int m ) noexcept
    -> std::chrono::month_weekday;
(15) (自 C++20)
month_weekday_last
constexpr auto operator/( const std::chrono::month& m,

                          const std::chrono::weekday_last& wdl ) noexcept

    -> std::chrono::month_weekday_last;
(16) (自 C++20)
constexpr auto operator/( int m, const std::chrono::weekday_last& wdl ) noexcept
    -> std::chrono::month_weekday_last;
(17) (自 C++20)
constexpr auto operator/( const std::chrono::weekday_last& wdl,

                          const std::chrono::month& m ) noexcept

    -> std::chrono::month_weekday_last;
(18) (自 C++20)
constexpr auto operator/( const std::chrono::weekday_last& wdl, int m ) noexcept
    -> std::chrono::month_weekday_last;
(19) (自 C++20)
year_month_day
constexpr auto operator/( const std::chrono::year_month& ym,

                          const std::chrono::day& d ) noexcept

    -> std::chrono::year_month_day;
(20) (自 C++20)
constexpr auto operator/( const std::chrono::year_month& ym, int d ) noexcept
    -> std::chrono::year_month_day;
(21) (自 C++20)
constexpr auto operator/( const std::chrono::year& y,

                          const std::chrono::month_day& md ) noexcept

    -> std::chrono::year_month_day;
(22) (自 C++20)
constexpr auto operator/( int y, const std::chrono::month_day& md ) noexcept
    -> std::chrono::year_month_day;
(23) (自 C++20)
constexpr auto operator/( const std::chrono::month_day& md,

                          const std::chrono::year& y ) noexcept

    -> std::chrono::year_month_day;
(24) (自 C++20)
constexpr auto operator/( const std::chrono::month_day& md, int y ) noexcept
    -> std::chrono::year_month_day;
(25) (自 C++20)
year_month_day_last
constexpr auto operator/( const std::chrono::year_month& ym,

                         std::chrono::last_spec ) noexcept

    -> std::chrono::year_month_day_last;
(26) (自 C++20)
constexpr auto operator/( const std::chrono::year& y,

                          const std::chrono::month_day_last& mdl ) noexcept

    -> std::chrono::year_month_day_last;
(27) (自 C++20)
constexpr auto operator/( int y, const std::chrono::month_day_last& mdl ) noexcept
    -> std::chrono::year_month_day_last;
(28) (自 C++20)
constexpr auto operator/( const std::chrono::month_day_last& mdl,

                          const std::chrono::year& y ) noexcept

    -> std::chrono::year_month_day_last;
(29) (自 C++20)
constexpr auto operator/( const std::chrono::month_day_last& mdl, int y ) noexcept
    -> std::chrono::year_month_day_last;
(30) (自 C++20)
year_month_weekday
constexpr auto operator/( const std::chrono::year_month& ym,

                          const std::chrono::weekday_indexed& wdi ) noexcept

    -> std::chrono::year_month_weekday;
(31) (自 C++20)
constexpr auto operator/( const std::chrono::year& y,

                          const std::chrono::month_weekday& mwd ) noexcept

    -> std::chrono::year_month_weekday;
(32) (自 C++20)
constexpr auto operator/( int y, const std::chrono::month_weekday& mwd ) noexcept
    -> std::chrono::year_month_weekday;
(33) (自 C++20)
constexpr auto operator/( const std::chrono::month_weekday& mwd,

                          const std::chrono::year& y ) noexcept

    -> std::chrono::year_month_weekday;
(34) (自 C++20)
constexpr auto operator/( const std::chrono::month_weekday& mwd, int y ) noexcept
    -> std::chrono::year_month_weekday;
(35) (自 C++20)
year_month_weekday_last
constexpr auto operator/( const std::chrono::year_month& ym,

                          const std::chrono::weekday_last& wdl ) noexcept

    -> std::chrono::year_month_weekday_last;
(36) (自 C++20)
constexpr auto operator/( const std::chrono::year& y,

                          const std::chrono::month_weekday_last& mwdl ) noexcept

    -> std::chrono::year_month_weekday_last;
(37) (自 C++20)
constexpr auto operator/( int y, const std::chrono::month_weekday_last& mwdl ) noexcept
    -> std::chrono::year_month_weekday_last;
(38) (自 C++20)
constexpr auto operator/( const std::chrono::month_weekday_last& mwdl,

                          const std::chrono::year& y ) noexcept

    -> std::chrono::year_month_weekday_last;
(39) (自 C++20)
constexpr auto operator/( const std::chrono::month_weekday_last& mwdl, int y ) noexcept
    -> std::chrono::year_month_weekday_last;
(40) (自 C++20)

这些 operator/ 重载提供了一种创建 推算格里高利历 日期。

要创建完整的日期,可以接受以下三种顺序中的任何一种

  • year/month/day,
  • month/day/year,
  • day/month/year.

在每种情况下,day 可以用以下之一替换

  • std::chrono::last,用于该月的最后一天;
  • weekday[i],用于该月的第 iweekday
  • weekday[std::chrono::last],用于该月的最后一个 weekday

如果其含义可以从其他操作数的类型中明确确定,则可以接受一个普通整数:2005y/4/5 是允许的,但 5/April/2005 不是。

部分日期类型 (year_monthmonth_day 等) 可以通过在三种顺序中的任何一种中不应用第二个 operator/ 来创建。

[edit] 返回值

20) std::chrono::year_month_day(ym.year(), ym.month(), d)
21) std::chrono::year_month_day(ym.year(), ym.month(), std::chrono::day(d))
22,24) std::chrono::year_month_day(y, md.month(), md.day())
23,25) std::chrono::year_month_day(std::chrono::year(y), md.month(), md.day())
31) std::chrono::year_month_weekday(ym.year(), ym.month(), wdi)
32,34) std::chrono::year_month_weekday(y, mwd.month(), mwd.weekday_indexed())
33,35) std::chrono::year_month_weekday(std::chrono::year(y), mwd.month(), mwd.weekday_indexed())
36) std::chrono::year_month_weekday_last(ym.year(), ym.month(), wdl)
37,39) std::chrono::year_month_weekday_last(y, mwdl.month(), mwdl.weekday_last())
38,40) std::chrono::year_month_weekday_last(std::chrono::year(y), mwdl.month(), mwdl.weekday_last())

[编辑] 示例

#include <chrono>
using namespace std::chrono;
 
constexpr auto ym{2021y/8};
static_assert(ym == year_month(year(2021), August));
 
constexpr auto md{9/15d};
static_assert(md == month_day(September, day(15)));
 
constexpr auto mdl{October/last};
static_assert(mdl == month_day_last(month(10)));
 
constexpr auto mw{11/Monday[3]};
static_assert(mw == month_weekday(November, Monday[3]));
 
constexpr auto mwdl{December/Sunday[last]};
static_assert(mwdl == month_weekday_last(month(12), weekday_last(Sunday)));
 
// Those 3 year/month/day orders that people actually use on this planet and beyond:
constexpr auto ymd{year(2021)/January/day(23)};
static_assert(ymd == month{1}/23/2021);
static_assert(ymd == day{23}/1/2021);
static_assert(ymd == year_month_day(2021y, month(January), 23d));
 
int main() {}