简体   繁体   English

如何将 chrono::year_month_day 添加到 chrono::sys_seconds

[英]How to add chrono::year_month_day to chrono::sys_seconds

Am holding duration's in a year_month_day.我持有年月日的持续时间。 Is there a simple way to add the year_month_day duration to a time_point like sys_seconds?有没有一种简单的方法可以将 year_month_day 持续时间添加到像 sys_seconds 这样的 time_point?

sys_seconds date1 = {};
sys_seconds dat2 = {};
year_month_day calDuration;
date1 = date2 + calDuration;    //error: no match for ‘operator+’ 

This is chrono catching logic bugs for you at compile-time.这是在编译时为您捕获逻辑错误的时间。 Adding date2 + calDuration is akin to adding tomorrow + today.添加date2 + calDuration类似于添加明天 + 今天。 It just doesn't make sense.这没有任何意义。 And that's why it is a compile-time error.这就是为什么它是一个编译时错误。

What you may mean is that you have durations years , months and days .你可能的意思是你有yearsmonthsdays的持续时间。 This is not the same as the similarly named types year , month and day .这与名称相似的类型yearmonthday不同。 The plural forms are chrono::duration s, just like minutes and nanoseconds .复数 forms 是 chrono chrono::duration s,就像minutesnanoseconds一样。 days is 24h . days24h And years and months are the average length of those units in the civil calendar. yearsmonths是这些单位在民用日历中的平均长度。

Conversely, the singular forms year , month and day are the calendrical components that give a name to a day in the civil calendar, eg 2020y , December , and 18d .相反,单数 forms yearmonthday是为民用日历中的一天命名的日历组件,例如2020yDecember18d And it is these singular forms that make up a year_month_day , eg 2020y/December/18d .正是这些奇异的 forms 构成了year_month_day ,例如2020y/December/18d

See this SO answer for a deep-dive on the difference between month and months .请参阅此 SO 答案以深入了解monthmonths之间的区别。

There are multiple ways to add the units years and months to a time_point .有多种方法可以将单位yearsmonths添加到time_point See this SO answer for a deep-dive on that topic.请参阅此 SO 答案以深入了解该主题。

暂无
暂无

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

相关问题 如何从 C++ 中的 std::chrono::year_month_day 获取星期几 - How to get the weekday number from std::chrono::year_month_day 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? 使用Howard Hinnant的日期库将日时信息添加到year_month_day - Add time of day information to year_month_day with Howard Hinnant's date library 使用boost :: chrono,如何从单独的年,月,日,时,分,秒分别计算自纪元UTC以来的毫秒数 - Using boost::chrono, how to calculate milliseconds since epoch UTC from separate year, month, day, hour,min,secs 如何构建chrono :: year对象? - How is a chrono::year Object Constructed? 从C ++中的std :: chrono :: time_point中提取年/月/日等 - Extract year/month/day etc. from std::chrono::time_point in C++ C++ 20 chrono:如何比较 time_point 和 month_day? - C++ 20 chrono: How to compare time_point with month_day? 为什么不能将 `std::chrono::hours` 添加到 `std::chrono::sys_days` - Why is it not possible to add a `std::chrono::hours` to a `std::chrono::sys_days`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM