Get Date And Time From A Time Server

Get Date And Time From A Time Server
<?php # PHP V4
function query_time_server( $timeserver, $socket )
{
/* Query a time server
(C) 1999-09-29, Ralf D. Kloth (QRQ.software) <ralf at qrq.de> */
$fp = @fsockopen( $timeserver, $socket, $err, $errstr, 5 );
# parameters: server, socket, error code, error text, timeout
if ( $fp )
{
fputs( $fp, “\n” );
$timevalue = fread( $fp, 49 );
fclose($fp); # close the connection
}
else
{
$timevalue = ” “;
}
$ret = array();
$ret[] = $timevalue;
$ret[] = $err;     # error code
$ret[] = $errstr;  # error text
return( $ret );
} # function query_time_server
?>
<?php
/* Query a time server
(C) 1999-09-29, Ralf D. Kloth (QRQ.software) <ralf at qrq.de> */
$timeserver = “time-C.timefreq.bldrdoc.gov”;
$timercvd = query_time_server($timeserver,13);
if ( !$timercvd[ 1 ] )
{
# if no error from query_time_server
$timevalue = $timercvd[ 0 ];
echo “Time check from time server “, $timeserver, ” : [<font color=\”red\”>”, $timevalue, “</font>].<br>\n”;
} #if (!$timercvd)
else
{
echo “Unfortunately, the time server $timeserver could not be reached at this time. “;
echo “$timercvd[1] $timercvd[2].<br>\n”;
} # else
?>
<?php
/* Query a time server
(C) 1999-09-29, Ralf D. Kloth (QRQ.software) <ralf at qrq.de> */
$timeserver = “time-C.timefreq.bldrdoc.gov”;
$timercvd = query_time_server( $timeserver, 37 );
if( !$timercvd[ 1 ] )
{
# if no error from query_time_server
$timevalue = bin2hex ( $timercvd[ 0 ] );
$timevalue = abs ( HexDec( ‘7fffffff’ ) – HexDec( $timevalue ) – HexDec( ‘7fffffff’ ) ) ;
$tmestamp = $timevalue – 2208988800; # convert to UNIX epoch time stamp
$datum = date( “Y-m-d ( D ) H:i:s”, $tmestamp – date( “Z”, $tmestamp ) ); /* incl time zone offset */
$doy = ( date( “z”, $tmestamp ) + 1 );
echo “Time check from time server “, $timeserver, ” : [<font color=\”red\”>”, $timevalue, “</font>]”;
echo ” (seconds since 1900-01-01 00:00.00).<br>\n”;
echo “The current date and universal time is “, $datum, ” UTC. “;
echo “It is day “, $doy, ” of this year.<br>\n”;
echo “The unix epoch time stamp is $tmestamp.<br>\n”;
} #if (!$timercvd)
else
{
echo “Unfortunately, the time server $timeserver could not be reached at this time. “;
echo $timercvd[ 1 ] . ” ” . $timercvd[ 2 ] . “<br>\n”;
} # else
?>

Short list of time servers

time.nrc.ca ports 37, NTP
ptbtime1.ptb.de ports 13 (local time), 37, NTP
ptbtime2.ptb.de ports 13 (local time), 37, NTP
ntp0.fau.de ports 37, NTP
ntps1-0.cs.tu-berlin.de ports 13 (local time), 37, NTP
ntps1-1.cs.tu-berlin.de ports 13 (local time), 37, NTP
ntps1-0.uni-erlangen.de ports 37, NTP
ntp-p1.obspm.fr ports 13, 37, NTP
time.ien.it ports 13 (local time), 37
ntp.iriti.cnr.it ports 13 (local time), NTP
NIST – US National Institute of Standards and Technology – www.boulder.nist.gov/
time-a.timefreq.bldrdoc.gov ports 13, 37
time-b.timefreq.bldrdoc.gov ports 13, 37
time-c.timefreq.bldrdoc.gov ports 13, 37
time-d.timefreq.bldrdoc.gov ports 13, 37
USNO – U.S. Naval Observatory – www.usno.navy.mil/, tycho.usno.navy.mil/ntp.html
tick.usno.navy.mil ports 13, 37, NTP
tock.usno.navy.mil ports 13, 37, NTP
ntp2.usno.navy.mil ports 13, 37, NTP
gnomon.cc.columbia.edu ports 13, 37, NTP
tick.gatech.edu ports 13, 37, NTP

A List of public NTP servers can be found at http://www.eecis.udel.edu/~mills/ntp/servers.html.
Use secondary NTP servers (stratum 2) whenever possible.
Linked»»

Advertisements
By Rz Rasel Posted in Php

21 comments on “Get Date And Time From A Time Server

  1. Browsing reddit.com I noticed your site bookmarked as: Get Date And Time From A Time Server | arzrasel. I’m assuming you book-marked it yourself and wanted to ask if social bookmarking gets you a lot of site visitors? I’ve been looking at doing some bookmarking for a few of my sites but wasn’t sure if it would generate any positive results. Appreciate it.

  2. Hello just thought i would tell you something.. This is twice now i’ve landed on your blog in the last 2 days searching for completely unrelated things. Spooky or what?

  3. I don’t even know how I ended up right here, however I thought this post was once good. I do not recognize who you are however definitely you are going to a well-known blogger for those who aren’t already 😉 Cheers!

  4. fantastic post, very informative. I wonder why the other specialists of this sector don’t notice this. You should continue your writing. I am sure, you’ve a great readers’ base already!

  5. I’m very happy to read this. This is the kind of manual that needs to be given and not the random misinformation that’s at the other blogs. Appreciate your sharing this greatest doc.

  6. I have been exploring for a little bit for any high quality articles or blog posts on this sort of area . Exploring in Yahoo I at last stumbled upon this website. Reading this info So i’m happy to convey that I’ve an incredibly good uncanny feeling I discovered just what I needed. I most certainly will make sure to do not forget this site and give it a glance regularly.

  7. Hello just thought i would tell you something.. This is twice now i’ve landed on your blog in the last 2 days looking for totally unrelated things. Spooky or what?

  8. Hello there, just was aware of your weblog thru Google, and located that it is truly informative. I’m gonna be careful for brussels. I will be grateful when you proceed this in future. Many other people will likely be benefited from your writing. Cheers!

  9. I feel that is one of the so much significant information for me. And i am happy studying your article. But wanna observation on few normal issues, The website taste is wonderful, the articles is actually nice : D. Just right activity, cheers

  10. Thanks a bunch for sharing this with all people you really understand what you are speaking about! Bookmarked. Please additionally consult with my web site =). We can have a hyperlink exchange arrangement between us!

  11. This may be isn’t the best place to ask, I’m looking for a good chiropractor because I need a good one, I wanted reviews or info on Woolston Wellness Center 9832 North Hayden Road Scottsdale, AZ 85258 (480) 556-6797

  12. A fascinating discussion is definitely worth comment. I do believe that you should write more about this subject, it might not be a taboo subject but typically people don’t speak about these subjects. To the next! All the best!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s