当前位置 : 主页 > 网络编程 > PHP >

php获取授时服务器时间 time zone

来源:互联网 收集:自由互联 发布时间:2021-07-03
《php获得可靠的精准的当前时间 ( 通过授时服务器 )》收藏用。来自:http://justcoding.iteye.com/blog/843645 返回字段说明:http://www.nist.gov/pml/div688/grp40/its.cfm $fp=fsockopen('time.nist.gov',13,$errno,$e
《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);  
}

网友评论