PDA

View Full Version : It's 5:00 Somewhere



bluewalrus
11-03-2011, 12:17 AM
1) CODE TITLE: Where's it 5:00 PM?

2) AUTHOR NAME/NOTES:

3) DESCRIPTION: Shows where in the world it is currently 5:00pm

4) URL TO CODE:

or, ATTACHED BELOW (see #3 in guidelines below):


<?php
for ($zone = 0; $zone <24; $zone++) {
if ($zone < 12) {
// east right (Europe)
$symbol = "+";
$minus = 0;
} else {
// west left (Americas)
$symbol = "-";
$minus = 12;
}
date_default_timezone_set('Etc/GMT' . $symbol . ($zone - $minus));
$hours = date('G'); // current time in the zone
if ($hours == 17) {
date_default_timezone_set('Etc/GMT+0');
$gmt = date('G'); // time in green which long 0
while ($gmt != $hours ) {
if ($zone > 12) {
// west left (Americas)
$gmt--;
$long = $long + 15;
} else {
// east right (Europe)
$long = $long + 15;
$gmt++;
}
}
if ($zone > 12)
$long = '-' . $long;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(42, <?php echo $long;?>);
var myOptions = {
zoom: 2,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title:"It's 5 PM Here!"
});
}
</script>
</head>
<body onLoad="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>

bluewalrus
11-03-2011, 12:01 PM
I did part of this wrong, it goes into a loop if it's on the eastern side, will adjust...