How do I convert boost::posix_time::ptime to time_t?(如何将 boost::posix_time::ptime 转换为 time_t?)
问题描述
是否有一些标准"的方法,或者我能做的最好的方法是通过从 gregorian::date(1970,1,1) 中减去来直接计算它?
time_t
是用于以秒为单位(通常是纪元时间)保持时间的类型.我猜你是在纪元时间之后,如果是这样的话,除了你已经进行的减法之外,我不知道有任何方法可以直接获得纪元时间.一旦你有了 time_duration
(减法的结果),你就可以在持续时间上调用 total_seconds()
并将其存储在 time_t
中.>
顺便说一句.如果你在时代之后,你可以简单地使用 gettimeofday()
并为自己省去一些麻烦!
Is there some "standard" way or the best I can do is to compute it directly by subtracting from gregorian::date(1970,1,1)
?
time_t
is the type used to hold time in seconds (typically epoch time). I'm guessing you are after epoch time, if so I'm not aware of any way in boost of actually getting epoch time directly, aside from the subtraction you have already. Once you have a time_duration
(result of the subtraction), you can call total_seconds()
on the duration and store that in time_t
.
btw. if you are after epoch time, you could simple use gettimeofday()
and save yourself some headache!
这篇关于如何将 boost::posix_time::ptime 转换为 time_t?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将 boost::posix_time::ptime 转换为 time_t?


- C++ 协变模板 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 从python回调到c++的选项 2022-11-16
- 如何对自定义类的向量使用std::find()? 2022-11-07
- STL 中有 dereference_iterator 吗? 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01