php获取授时服务器时间 time zone
程序员文章站
2022-05-24 19:42:23
...
《php获得可靠的精准的当前时间(通过授时服务器)》收藏用。来自:http://justcoding.iteye.com/blog/843645 返回字段说明:http://www.nist.gov/pml/div688/grp40/its.cfm 无 $fp=fsockopen('time.nist.gov',13,$errno,$errstr,90); $ufc = explode(' ',fread
《php获得可靠的精准的当前时间 ( 通过授时服务器 )》收藏用。来自:http://justcoding.iteye.com/blog/843645
返回字段说明:http://www.nist.gov/pml/div688/grp40/its.cfm
$fp=fsockopen('time.nist.gov',13,$errno,$errstr,90); $ufc = explode(' ',fread($fp,date('Y'))); $date = explode('-',$ufc[1]); $processdate = $date[1].'-'.$date[2].'-'. date('Y').' '.$ufc[2]; switch($ufc[5]) { case 0: echo '精确'; break; case 1: echo '误差:0-5s'; break; case 2: echo '误差: > 5s'; break; default: echo '硬件出错!'; break; } echo gmttolocal($processdate,8); // 中国 function gmttolocal($mydate,$mydifference) { $datetime = explode(" ",$mydate); $dateexplode = explode("-",$datetime[0]); $timeexplode = explode(":",$datetime[1]); $unixdatetime = mktime($timeexplode[0]+$mydifference,$timeexplode[1],0,$dateexplode[0],$dateexplode[1],$dateexplode[2]); return date("m/d/Y H:i:s",$unixdatetime); }
上一篇: mysql基本语句_MySQL
下一篇: 如何优化查询逻辑?