本文介紹了從 TimeServer 獲取時間的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我正在嘗試從 NIST 時間服務器獲取時間.我怎樣才能做到這一點.我可以使用任何語言,但我更喜歡 php
I am trying to get the Time from a NIST timeserver. How can I do this. I can use any language but I prefer php
推薦答案
<?php
/* Query a time server
(C) 1999-09-29, Ralf D. Kloth (QRQ.software) <ralf at qrq.de> */
$timeserver = "ntp1.sf-bay.org";
$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>
";
echo "The current date and universal time is ",$datum," UTC. ";
echo "It is day ",$doy," of this year.<br>
";
echo "The unix epoch time stamp is $tmestamp.<br>
";
} #if (!$timercvd)
else {
echo "Unfortunately, the time server $timeserver could not be reached at this time. ";
echo "$timercvd[1] $timercvd[2].<br>
";
} # else
?>
來源
這篇關于從 TimeServer 獲取時間的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!