std :: chrono将天添加到当前日期 [英] std::chrono add days to current date

查看:81
本文介绍了std :: chrono将天添加到当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用std :: chrono来找到基于到期期限的将来计算日期。

I would like to use std::chrono in order to find calculate the date in the future based on an expiration period.

到期期限是一个整数,该整数表示指定从现在开始的天数。那么,如何使用chrono lib来查找100天后的日期?

The expiration period is an integer that specifies "days from now". So how do I use chrono lib in order to find the date after 100 days?

推荐答案

说您有 time_point 。要向该对象添加天数,只需将 operator + std :: chrono :: hours 一起使用:

#include <chrono>
std::chrono::system_clock::time_point t = std::chrono::system_clock::now();
std::chrono::system_clock::time_point new_t = t + std::chrono::hours(100 * 24);

这篇关于std :: chrono将天添加到当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆