tags:

views:

105

answers:

2

hello, i just want to ask if where can we find the code that will display the world clock just like this one LINK that doesn't depend on my computer time..

is there any plugins for that? or a function that i can simply call.. ?

any help will be much appreciated..

+1  A: 

Javascript: http://www.proglogic.com/code/javascript/time/worldclock.php

Probably too involved: http://worldtimeengine.com/api/code

Probably not too hard to do it yourself, PHP has pretty good date functions that when used with the correct timezone would allow you to easily get the time for any region in the world.

Example: (from http://www.bigresource.com/Tracker/Track-php-thNhheBb/)

<?php

$tz = date("Z");  //timezone offset of server in seconds

$est  = 3600 * -5;  // -0500 gmt
$cst  = 3600 * -6;
$mst  = 3600 * -7;
$pst  = 3600 * -8;
$hast = 3600 * -10;

// add (or subtract) the appropriate number of seconds from the offset to recalculate the time
echo date("h:i A", strtotime("now +" . ($hast - $tz) . " seconds"));

?> 

http://php.net/manual/en/timezones.php

You could combine this with GeoIP, which is a module for apache / php that uses the MaxMind database to resolve location information from your visitor's IP.

Michael Robinson
it still depends on my computer time.. :) but thank you for the reply..
vrynxzent
If javascript, it will depend on your computer time (unless it's AJAX). If it's PHP, it will depend on the server's time.
Michael Robinson
i tried thi http://worldtimeengine.com/api/code last time but in the directions, i need to sign up with the two links which is the API from worldtimeengine ang googlemap API.. i cant even find where they put the links for the registration.. is it free to register? :)
vrynxzent
how about this one.. http://www.timeanddate.com/worldclock/fullscreen.html?n=145 can i rip the time from thier website to my server?
vrynxzent
Why? It would probably take you less time to make it yourself!
Michael Robinson
its because when i set my computer time to +2hours, the time on my server would probably change also right? so in that case, i cant track for the exact time that the visitor visits my page if they're computer clock was not set to right time.. :) did you get my point sir?
vrynxzent
Your server clock is in no way related to your computer, unless the computer you are referring to as 'yours' is in fact also your server. The only way you can reliably track the exact time your user hits your site is by using your server time. It is up to you to ensure this time is accurate. If you wish, you can convert the 'hit time' depending on any GeoIP information you also collect, to give the user's time. Assuming they're not using a proxy. Or the GeoIP data is wrong. It will never be 100% exact. Using server time is your best bet.
Michael Robinson
i will try to use that.. :) thanks for the suggestions sir..
vrynxzent
A: 

Have your PHP function spit out the server's time, which you can then paste into a Javascript block in the generated page to initialize your client-side clock. As long as latency between the server and client isn't too horrible, this should give you a client-side clock synched to the server to within a few seconds.

<?php

$now = date('U') * 1000; // Unix timestamp in milliseconds

?>

<script type="text/javascript">
    var now = new Date(<?php echo $now ?>);
</script>

You can also periodically sync clocks via an AJAX call to retrieve the server-side timestamp and update the client with now.setTime().

Marc B