欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

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

程序员文章站 2022-05-12 17:34:15
...

《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);  
}