如何转换的boost ::了posix_time ::分组时间到time_t的? [英] How do I convert boost::posix_time::ptime to time_t?

查看:625
本文介绍了如何转换的boost ::了posix_time ::分组时间到time_t的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一些标准的方式,或我能做的最好的就是直接从阳历减去日期::计算它(1970,1,1) <? / p>

解决方案

time_t的是用来存放在几秒钟的时间类型(通常是划时代的时间)。我是从你已经减去猜测你是划时代的时间后,如果是这样,我不知道在实际直接得到划时代的时间提升任何方式,一边。一旦你有一个 TIME_DURATION (减法的结果),你可以调用 total_seconds()的持续时间和商店在 time_t的

BTW。如果你是划时代的时间后,你可以简单的使用函数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 ::分组时间到time_t的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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