我确定这个问题在其他地方得到了回答,但我无法在 Google 或 SO 上找到它,所以这里是。
在C/C++中,我想将相对时间转换成dd-hh:mm:ss格式的相对时间
ps -o etime
到绝对 UTC 格式的日期。
这看起来并不难。假设我已经有一个函数来生成以 struct tm 格式存储的相对时间:
struct tm *starting_rel_time = my_reltime_converstion(...);
time_t t = time(0);
struct tm *current_abs_time = localtime(&t);
我想要的基本上是 difftime 的对立面:
struct *tm starting_abs_time = current_abs_time - starting_rel_time;
现在,我可以编写自己的函数来进行转换,但由于所有进位操作和特殊条件(闰年等),这是一场噩梦。在 C/C++ 库中肯定有一种方法可以做到这一点吗?
最佳答案
使用Boost::Date_Time图书馆。
关于c++ - 在 C++ 中添加两个日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12566150/