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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:26:52+00:00 2026-05-16T01:26:52+00:00

i have managed to make a NTP request and retrieve the server time from

  • 0

i have managed to make a NTP request and retrieve the server time from it’s NTP response.
i want to convert this number to a Human-readable time, writing in C++.
can some one help me ?
as example you can look at:
http://www.4webhelp.net/us/timestamp.php?action=stamp&stamp=771554255&timezone=0
once you set the timestamp to 771554255 you’ll get “29/7/2010 13:14:32”.
i wanna do the same in my code,
any help ?

  • 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-16T01:26:53+00:00Added an answer on May 16, 2026 at 1:26 am

    It’s not C++, but here’s a perl implementation. Converting this into C++ should be no big deal:

    http://www.ntp.org/ntpfaq/NTP-s-related.htm#AEN6780

    # usage: perl n2u.pl timestamp
    # timestamp is either decimal: [0-9]+.?[0-9]*
    # or hex: (0x)?[0-9]+.?(0x)?[0-9]*
    
    # Seconds between 1900-01-01 and 1970-01-01
    my $NTP2UNIX = (70 * 365 + 17) * 86400;
    
    my $timestamp = shift;
    die "Usage perl n2u.pl timestamp (with or without decimals)\n"
        unless ($timestamp ne "");
    
    my ($i, $f) = split(/\./, $timestamp, 2);
    $f ||= 0;
    if ($i =~ /^0x/) {
        $i = oct($i);
        $f = ($f =~ /^0x/) ? oct($f) / 2 ** 32 : "0.$f";
    } else {
        $i = int($i);
        $f = $timestamp - $i;
    }
    
    my $t = $i - $NTP2UNIX;
    while ($t < 0) {
        $t += 65536.0 * 65536.0;
    }
    
    my ($year, $mon, $day, $h, $m, $s) = (gmtime($t))[5, 4, 3, 2, 1, 0];
    $s += $f;
    
    printf("%d-%02d-%02d %02d:%02d:%06.3f\n",
           $year + 1900, $mon+1, $day, $h, $m, $s);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have managed to make a surface from a set point points in vtk.
I want to make a panorama viewer in HTML5, I have managed to place
I have an assembly which I have managed to make visible to VB6 and
I am using a timer in xcode i have managed to make it count
I'm a newbie to jquery, but have managed to make a show-function and hover
with the help of resources of stackoverflow, i have managed to make autocomplete on
I have created some documents and managed to make some simple queries but I
I have managed to confuse myself whether I should return E_NOTIMPL or E_NOINTERFACE from
I have managed to make the last TD in each row unselectable in JQuery
I have managed to make my URL i18n compliant using Zend_Controller_Router . Ie: en/user/login

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.