2015-10-06 42 views
1

偏移我從https://timezonedb.com/download顯示GMT在PHP

一個時區數據庫

查詢每個時區行有一個TIME_START場和另一場名爲gmt_offset

例如一個行會

 [zone_id] => 191 
     [zone_name] => Asia/Kolkata 
     [country_name] => India 
     [time_start] => -891582800 
     [gmt_offset] => 23400 
     [dst] => 0 

我需要從這裏顯示的是國家和格林威治標準時間偏移這樣通過PHP

India: GMT +5:30 

我試過

  $plusoffset = $row->time_start+$row->gmt_offset; 
      $minusoffset = $row->time_start-$row->gmt_offset; 
      echo "Time Start: ". date('h:i:s',$row->time_start).'<br>'; 
      echo "Offset: ". date('h:i:s',$row->gmt_offset).'<br>'; 
      echo "Start+Offset: ". date('h:i:s',$plusoffset).'<br>'; 
      echo "Start-Offset: ". date('h:i:s',$minusoffset).'<br>'; 

但這些都不顯示正確的偏移量。

我敢肯定,我失去了一些東西昭然若揭,但我不能爲我的生命數字出來。

回答

1

你到了那裏(23400)秒就轉換到小時和分鐘......

$gmt_offset = 23400; 

$hours = (int)($gmt_offset/3600); 
$minutes = $gmt_offset % 3600/60; 
echo 'Offset: ' . $hours . ':' . $minutes; 
+0

它仍然顯示1小時額外費用。例如。而不是在5:30顯示它顯示6:30。 –

+1

23400肯定是6.5小時(你可以除以3600來看你自己) 你應該問爲什麼它是23400。 –