Home  >  Article  >  php教程  >  php获取授时服务器时间 time zone

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

WBOY
WBOYOriginal
2016-06-06 19:38:35973browse

《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);  
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn