Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3950556
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:37:31+00:00 2026-05-20T01:37:31+00:00

I would like to transfer a boost::posix_time::ptime over the network as a boost::int64_t .

  • 0

I would like to transfer a boost::posix_time::ptime over the network as a boost::int64_t. According to A way to turn boost::posix_time::ptime into an __int64, I can easily define my own epoch and only transfer the time_duration from that reference epoch as a 64 bits integer. But how to convert back to a ptime?

#include <iostream>
#include <cassert>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/gregorian/greg_month.hpp>

using namespace std;

using boost::posix_time::ptime;
using boost::posix_time::time_duration;
using boost::gregorian::date;

int main(int argc, char ** argv){
    ptime t = boost::posix_time::microsec_clock::local_time();

    // convert to int64_t
    ptime myEpoch(date(1970,boost::gregorian::Jan,1));
    time_duration myTimeFromEpoch = t - myEpoch;
    boost::int64_t myTimeAsInt = myTimeFromEpoch.ticks();

    // convert back to ptime
    ptime test = myEpoch + time_duration(myTimeAsInt);

    assert(test == t);
    return 0;
}

This is not working since the time_duration constructor taking a tick count as argument is private. I am also interested in any other way to simply transfer that ptime over simple data types.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:37:32+00:00Added an answer on May 20, 2026 at 1:37 am

    Working solution with millisecond resolution:

    int main(int argc, char ** argv){
        ptime t = boost::posix_time::microsec_clock::local_time();
    
        // convert to int64_t
        ptime myEpoch(date(1970,boost::gregorian::Jan,1));
        time_duration myTimeFromEpoch = t - myEpoch;
        boost::int64_t myTimeAsInt = myTimeFromEpoch.total_milliseconds();
    
        // convert back to ptime
        ptime test = myEpoch + boost::posix_time::milliseconds(myTimeAsInt);
    
        cout << test << endl;
        cout << t << endl;
    
        time_duration diff = test - t;
    
        assert(diff.total_milliseconds()==0);
        return 0;
    }
    

    Thanks 12a6.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a reusable interface to transfer some proprietary information over
I would like to know the best way to transfer data from a web
I would like to know, wether Server.Transfer will work in a Web Farm. Thanking
In my Java application I would like to download a JPEG, transfer it to
I have a large mysql table that I would like to transfer to a
I am writing a data transfer application using a servlet and would like to
I would like to send data over internet through a desktop application. I know
I would like to transfer my existing SQL Azure location to other one, but
I would like to implement a thread pool in Java, which can dynamically resize
We have a website we would like to transfer to our Server 2008, IIS7

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.