Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::chrono::weekday::weekday

      From cppreference.com
      <cpp‎ |chrono‎ |weekday
       
       
      Date and time library
       
       
      weekday()=default;
      (1)(since C++20)
      constexprexplicit weekday(unsigned wd)noexcept;
      (2)(since C++20)
      constexpr weekday(conststd::chrono::sys_days& sd)noexcept;
      (3)(since C++20)
      constexprexplicit weekday(conststd::chrono::local_days& ld)noexcept;
      (4)(since C++20)

      Constructs aweekday object.

      1) Default constructor leaves the weekday value uninitialized.
      2) Constructs aweekday object holding the weekday valuewd. Ifwd==7, the value held is0. Ifwd>255, the value held is unspecified.
      3) Constructs aweekday object representing the day of the weeksd corresponds to. This constructor defines an implicit conversion fromstd::chrono::sys_days toweekday.
      4) Constructs aweekday object representing the day of the weekld corresponds to, as if byweekday(std::chrono::sys_days(ld.time_since_epoch())).

      [edit]Parameters

      wd - a weekday value
      sd - a system days object
      ld - a local days object

      [edit]Example

      Run this code
      #include <chrono>#include <iomanip>#include <iostream> int main(){constexprstd::chrono::weekday friday{5};// uses overload (2)    static_assert(friday==std::chrono::Friday); for(int y{2020}; y<=2024;++y){conststd::chrono::year cur_year{y};for(int cur_month{1}; cur_month!=13;++cur_month){conststd::chrono::year_month_day ymd{cur_year/cur_month/13};conststd::chrono::weekday cur_weekday{std::chrono::sys_days(ymd)};// (3)if(cur_weekday== friday)std::cout<< ymd<<" is "<< friday<<'\n';}}}

      Output:

      2020-03-13 is Fri2020-11-13 is Fri2021-08-13 is Fri2022-05-13 is Fri2023-01-13 is Fri2023-10-13 is Fri2024-09-13 is Fri2024-12-13 is Fri
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/chrono/weekday/weekday&oldid=176093"

      [8]ページ先頭

      ©2009-2025 Movatter.jp