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

后端 未结 4 1347
旧巷少年郎
旧巷少年郎 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:02

    #include 
    
    // ...
    
    uint64_t secondsSinceEpoch(const boost::posix_time::ptime& time) {
        namespace bpt = boost::posix_time;
        const bpt::ptime epoch = bpt::from_time_t(0);
        bpt::time_duration duration = time - epoch;
        return duration.total_seconds();
    }
    
    // ...
    
    namespace bpt = boost::posix_time;
    const bpt::ptime now = bpt::second_clock::local_time();
    uint64_t seconds = secondsSinceEpoch(now);
    std::cout << "seconds: " << seconds << std::endl;
    

提交回复
热议问题