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 6249219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:11:48+00:00 2026-05-24T13:11:48+00:00

I’ve seen some other answers on SO that suggest we can get the time

  • 0

I’ve seen some other answers on SO that suggest we can get the time from epoch in milliseconds by subtracting the epoch time from the "other" time, but it doesn’t work when I try it:

ptime epoch = time_from_string("1970-01-01 00:00:00.000");
ptime other = time_from_string("2011-08-09 17:27:00.000");

long diff = (other-epoch).total_milliseconds();

At this stage diff is -1349172576 and it should be a positive number since the "other" time is 2011. Does anybody know what might be causing this? What’s the proper way to get the milliseconds since epoch?

Additionally, I’ve tried to construct a ptime object from milliseconds:

ptime result = from_time_t(diff);

Result then becomes: "1927-Apr-01 13:50:24" and it should be "2011-Aug-09 17:27:00.000". What’s the catch here?

Update:

OK, so my mistake stems from the fact that I have 2 programs, one is C# (8 byte/64-bit long) and a C++ (4 byte/32-bit long); in any case, that interaction is not depicted here.

However, when I use long long, the value is positive but the resulting date (constructed from_time_t) is still incorrect: "2012-Oct-02 10:09:36".

  • 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-24T13:11:48+00:00Added an answer on May 24, 2026 at 1:11 pm

    Presumably you’re on a platform on which long is smaller than 64 bits.

    Let’s assume it’s 32 bits – in that case, the maximum value of a long is 2147483648. However, it’s been ~1312000000000 milliseconds since epoch, so long is clearly insufficient to hold this value and consequently you’re seeing overflow.

    I’d do something like this instead:

    ptime epoch = time_from_string("1970-01-01 00:00:00.000");
    ptime other = time_from_string("2011-08-09 17:27:00.000");
    
    time_duration const diff = other - epoch;
    long long ms = diff.total_seconds();
    ms *= 1000LL;
    ms += diff.fractional_seconds() / 1000000L; // 1000L if you didn't build datetime
                                                // with nanosecond resolution
    

    Creating a ptime from the specified number of milliseconds has the same problem – ptime works in terms of long and you have a long long – so you’ll essentially need to do the reverse:

    // given long long ms
    time_duration t = seconds(static_cast<long>(ms / 1000LL));
    if (ms % 1000LL)
        t += milliseconds(static_cast<long>(ms % 1000LL));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace

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.