简体   繁体   English

如何从 C++ 中的 std::chrono::year_month_day 获取星期几

[英]How to get the weekday number from std::chrono::year_month_day in C++

In C++ 20, the following code will output the number (0-6) for the weekday of the input date:在C++ 20,下面的代码将output这个数字(0-6)为输入日期的星期几:

#include <chrono>
#include <iostream>

int
main()
{
    using namespace std;
    using namespace std::chrono;
    year_month_day dmy;
    cin >> parse("%d %m %Y", dmy);
    cout << format("%w", weekday{dmy}) << '\n';
}

How can I get that number to use in code as a numeric value so I could use it in a calculation?我怎样才能让这个数字在代码中用作数值,以便我可以在计算中使用它? This has to be simple but I can't figure it out.这必须很简单,但我无法弄清楚。

int total_score = weekday{dmy} * 10;

As a side note, I am really using the date ( http://howardhinnant.github.io/date/date.html ) library created by Howard Hinnant in C++ 17 but I believe the same question applies to both.作为旁注,我实际上使用的是 Howard Hinnant 在 C++ 17 创建的日期 ( http://howardhinnant.github.io/date/date.html ) 库,但我相信同样的问题适用于两者。

You can usestd::chrono::weekday::c_encoding to retrieve the stored value.您可以使用std::chrono::weekday::c_encoding来检索存储的值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 chrono::year_month_day 添加到 chrono::sys_seconds - How to add chrono::year_month_day to chrono::sys_seconds 从C ++中的std :: chrono :: time_point中提取年/月/日等 - Extract year/month/day etc. from std::chrono::time_point in C++ 如何获取 std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> 来自年、月、日、小时、分钟和秒的变量?</std::chrono::system_clock,> - How to get std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> from variables of year,month,day,hour,minute and seconds? 用std :: chrono显示日,月和年? - Show day, month and year with std::chrono? 如何从年、月、日、小时、分钟、秒、毫秒中获取计时时间点? - How to get chrono time_point from year, month, day, hour, minute, second, millisecond? C ++如何从一个整数值获取三个单独的日期值(日,月,年) - C++ How to Get three separate date values (day, month, year) from one integer value 如何从 C++ Builder 6 中的 MonthCalendar 获取日期(日/月/年)? - How to get date (day/month/year) from MonthCalendar in C++ Builder 6? 如何比较C或C++中的日/月/年? - How to compare day/month/year in C or C++? C++ 20 chrono:如何比较 time_point 和 month_day? - C++ 20 chrono: How to compare time_point with month_day? 使用Howard Hinnant的日期库将日时信息添加到year_month_day - Add time of day information to year_month_day with Howard Hinnant's date library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM