2017-10-24 13:33
浏览 188

PHP - 按国家/地区名称获取时区

I want to get the time zone abbreviation of visitor and for this purpose i am using the below code:

$details = json_decode(file_get_contents("{$ip}/json"));
$visitor_country_code = $details->country . 'T';

From this i got the first two letters of country name and concatenated 'T'.But this is working only for few countries.I tested it by changing proxy and it worked for Pakistan and then i tried for USA and it gave me error

DateTimeZone::__construct(): Unknown or bad timezone (AEDT)

Can someone help me to get the country code of all countries?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dpqvwgr74759
    dpqvwgr74759 2017-10-24 14:04

    You can use[IP address] to get all the information you want.

    点赞 评论