C++:您如何打印与当前时间相距特定时间的日期
C++: How do you a print a date a specific amount of time away from the current time?
我正在试验ctime
但我一生都无法弄清楚如何打印距离当前日期 X 天的日期。这是我到目前为止的程序:
#include "header.h"
int main()
{
time_t current;
struct tm * timedata;
time(¤t);
timedata = localtime(¤t);
cout << "The current date and time is: " << asctime(timedata) << endl << endl;
return 0;
}
如果我是对的,time(¤t)
返回从 2000 年 1 月 1 日开始的秒数,但我得到的数字似乎太小了,无法做到这一点。所有的帮助都表示赞赏。
time(¤t) 返回自 1970 年 1 月 1 日 UTC -0000 以来的秒数。
添加 n*86400,以获取当前时间/之前 n 天的时间。
当然,前提是你不会跨越夏令时/冬令时调整,如果你碰巧生活在世界上遭受这种奇怪概念困扰的地区......
相关文章:
- 使用C++的日期库读取时间
- 如何找到两个日期之间的时间差异(以秒和纳秒为单位)?
- 为什么在C++中获取日期和/或时间如此复杂?
- 在 MacOS 上C++:显示日期和时间问题
- 如何将我的每个矢量字符串转换为纪元时间日期
- 将 unix 时间戳转换为人类可读的日期
- 使用霍华德·欣南特的日期库将时间信息添加到year_month_day
- 注册表-获取值(而不是键)上次更改的时间和键创建日期
- 我的C++程序如何访问计算机的日期和时间以打印和使用当前年份?
- 使用 C++将时间戳转换为格式化的日期时间
- C++代码的 C# 日期时间等效项是什么?
- 以毫秒级精度对日期和时间进行操作
- 如何在提升日期时间中创建日期范围?
- 将日期字符串转换为 unix 时间戳
- C 自定义时间日期结构到UTC时期
- 使用SNTP(Windows C )从服务器获取时间/日期
- C 的SNTP客户端的时间/日期
- 将文件名的文件另存为当前时间日期
- 在没有宏的情况下获取编译时间日期和时间
- C++应用程序构建时间/日期保存