【发布时间】:2015-08-17 10:44:05
【问题描述】:
我想定义一组每周 7 天的营业时间。当访问者访问网页时,我想显示特定国家(尼维斯、加勒比海)的当前时间和日期,然后将其与一组定义的打开时间进行比较,以显示两个标题之一 1)打开 2)关闭.具体来说,这是我想要制作的:
到目前为止,我一直在使用它来获取当前时间并设置数组,但是如何比较两者?
<?php
function get_timee($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=xxx");
$timez = json_decode($google_time);
$d = new DateTime("now", new DateTimeZone($timez->timeZoneId));
return $d->format('H:i');
}
$array = array(
"Monday" => "10:00 - 18:00",
"Tuesday" => "10:00 - 18:00",
"Wednesday" => "10:00 - 18:00",
"Thursday" => "10:00 - 18:00",
"Friday" => "18:00 - 23:00",
"Saturday" => "18:00 - 23:00",
"Sunday" => "Closed"
);
?>
它的<?php echo get_timee("Federation of Saint Kitts and Nevis","Nevis"); ?>。我们目前...
【问题讨论】:
-
您不应公开分享您的 API 密钥。
-
我删除了它,比尼维斯晚好一点。我的意思是永远不会。