<?php
foreach( array(
'US', 'CN', 'GB', 'DE', 'NL', 'FR', 'ES', 'IT', 'TR', 'RU', 'TW', 'HK', 'BR', 'KR', 'AE', 'TH', 'AU'
) as $code )
{
$timezone = geoip_time_zone_by_country_and_region($code)."\n";
$timezone = trim($timezone);
if(empty($timezone))
continue;
$dtz = new DateTimeZone($timezone);
$hourOffset = (int)( $dtz->getOffset(new DateTime('now', $dtz)) / 60 / 60 );
echo "Timezone: $timezone, $hourOffset hours\n";
}
結果:
Timezone: Europe/London, 1 hours
Timezone: Europe/Berlin, 2 hours
Timezone: Europe/Amsterdam, 2 hours
Timezone: Europe/Paris, 2 hours
Timezone: Europe/Rome, 2 hours
Timezone: Asia/Istanbul, 3 hours
Timezone: Asia/Taipei, 8 hours
Timezone: Asia/Hong_Kong, 8 hours
Timezone: Asia/Seoul, 9 hours
Timezone: Asia/Dubai, 4 hours
Timezone: Asia/Bangkok, 7 hours
其中有些國家的腹地廣,所以時間變化大,就無法查到,正解應該是要再搭配 region 資訊才行,請參考 php - geoip_time_zone_by_country_and_region
沒有留言:
張貼留言