本文介紹了從 TimeServer 獲取時(shí)間的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
限時(shí)送ChatGPT賬號(hào)..
我正在嘗試從 NIST 時(shí)間服務(wù)器獲取時(shí)間.我怎樣才能做到這一點(diǎn).我可以使用任何語(yǔ)言,但我更喜歡 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
?>
來(lái)源
這篇關(guān)于從 TimeServer 獲取時(shí)間的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!