A way to turn boost::posix_time::ptime into an __int64

后端 未结 4 1382
旧巷少年郎
旧巷少年郎 2021-01-04 01:34

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 th

4条回答
  •  醉话见心
    2021-01-04 02:18

    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();
    

提交回复
热议问题