打开的boost ::了posix_time ::分组时间到__int64的一种方法 [英] A way to turn boost::posix_time::ptime into an __int64
问题描述
有谁知道是否有转的好方法的boost ::了posix_time ::分组时间
到 __的Int64
值。 (我编了微秒的版本,而不是纳秒版本)。
Does anyone know if there is a good way to turn a boost::posix_time::ptime
into an __int64
value. (I have compiled the microsecond version, not the nanosecond version).
我需要以某种方式做到这一点,因为我希望存储所产生的 __的Int64
在联盟
键入它使用对于高性能应用的原始数据。某种类型的像这样的记忆碎片功能将是对我非常有用。我想避免的演员,如果可能的话,反而会求助于他们,如果我需要。
I need to do this somehow as I am looking to store the resulting __int64
in a union
type which uses the raw data for a high-performance application. Some type of Memento functionality like this would be highly useful for me. I'd like to avoid casts, if possible, but will resort to them if I need to.
推荐答案
一个分组时间转换为整数是相当意义的,因为分组时间的实际时间的抽象。一个整数基于时间就是那时候从一个时代的计数重新presentation。你(可能)想要做的是生成一个<一个href=\"http://www.boost.org/doc/libs/1%5F40%5F0/doc/html/date%5Ftime/posix%5Ftime.html#date%5Ftime.posix%5Ftime.time%5Fduration\">time_duration从你的时间,你有兴趣的时期,然后使用TIME_DURATION ::蜱()来获得64位整数。您可能需要你的结果扩展到你想要的precision:
Converting a ptime to an integer is rather meaningless, since ptime is an abstraction of the actual time. An integer based time is a representation of that time as a count from an epoch. What you (probably) want to do is generate a time_duration from your time to the epoch you are interested in, then use the time_duration::ticks() to get the 64-bit integer. You may have to scale your result to your desired precision:
ptime myEpoch(date(1970,Jan,1)); // Or whatever your epocj is.
time_duration myTimeFromEpoch = myTime - myEpoch;
boost::int64_t myTimeAsInt = myTimeFromEpoch.ticks();
这篇关于打开的boost ::了posix_time ::分组时间到__int64的一种方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!