PHP/Jquery中是否有任何API或插件,用于通过IP地址获取本地时间?我只有在我的网站上注册的所有用户的IP地址,如何仅通过IP地址获取该特定用户的本地时间?
这对
我有用
function get_localtime($country,$city)
{
$country = str_replace(' ', '', $country);
$city = str_replace(' ', '', $city);
$geocode_stats = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=$city+$country,&sensor=false");
$output_deals = json_decode($geocode_stats);
$latLng = $output_deals->results[0]->geometry->location;
$lat = $latLng->lat;
$lng = $latLng->lng;
$google_time = file_get_contents("https://maps.googleapis.com/maps/api/timezone/json?location=$lat,$lng×tamp=1331161200&key=AIzaSyAtpji5Vk271Qu6_QFSBXwK7wpoCQLY-zQ");
$timez = json_decode($google_time);
$d = new DateTime("now", new DateTimeZone($timez->timeZoneId));
return $d->format('H : i: s');
}
//------------------------------------------------------------------------------ Getting TimeZone by the Ip Address
$location = file_get_contents('http://api.ipinfodb.com/v3/ip-city/?key=xxxxxxxxxxx&ip=121.242.47.195&format=json');
//------------------------------------------------------------------------------
$location = json_decode($location,true);
if(is_array($location)){
echo get_timee("INDIA","MAHARASHTRA");
}else{
echo '{"statusCode":"error"}';
}
在此处注册免费密钥:http://ipinfodb.com/register.php(没有限制,但如果每秒超过 1 个请求,则排队)