surfsup Posted December 7, 2007 Share Posted December 7, 2007 This is a bit of a js question but the relevant bit am stugglling with is PHP I am using the following to create some clocks on a site that relational to the server clock time. THe script etc are here http://www.6times9.com/javascript/cheatclock/ The script essential takes the time from php and then adds 1 sec every sec. Using Clocks are defined using the cheatclock() function. Any number of these can be used, all contained within the run_cheatclock() function and separated by semi-colons. The values defined in the function are: the hour in 24-hour format, the minutes, the seconds, the timezone, and the ID of the span For example, for GMT: cheatclock(15, 00, 04, "GMT", "london"). The quotation marks around the timezone and ID are important. The full code (with as few, or as many, clocks as required) that needs to be placed at the end of the head section (and filled-in appropriately) is: <script type="text/javascript"> // Timezone Cheat Clock Setup function run_cheatclock(){ cheatclock(hour1, minute1, second1, "timezone1", "ID1"); cheatclock(hour2, minute2, second2, "timezone2", "ID2"); cheatclock(hour3, minute3, second3, "timezone3", "ID3"); } </script> <script type="text/javascript" src="cheatclock.js"></script> Once that is in the head section, place <span id="the ID specified"></span> where you want the clock to appear for each of the specified clocks. Note that an ID may occur only once in a page (i.e. if you want two clocks showing the same time, you will need to define them separately). I find pre-filling the span using PHP (or equivalent) causes the script to fail gracefully; if the browser supports JavaScript the value of the span is replaced by the script, and if the browser doesn't support JavaScript then the static time will remain. NOTE: Since there is no date, if a page using this function is displayed "when the clocks change" the time will be incorrect. However, it will correct itself when the page is reloaded as it will read new values from the server. I can get it to work but it always starts from 12.00. The support files say "the start time is specified using PHP (or similar) " How do I specify the time through php. I know how to get the time using php but don't know how i integrate it into this script I hope that makes sense THanks Quote Link to comment https://forums.phpfreaks.com/topic/80632-solved-cheatclock/ Share on other sites More sharing options...
boushley Posted December 7, 2007 Share Posted December 7, 2007 You said you know how to get the time in php... what are you doing to get the time? if you do something like <?php $hours = date(H); $minutes = date(i); $seconds = date(s); ?> and then echo each of those in their appropriate place. PS All of that came from... http://us3.php.net/manual/en/function.date.php Just went there and typed in time to the function search. Quote Link to comment https://forums.phpfreaks.com/topic/80632-solved-cheatclock/#findComment-408915 Share on other sites More sharing options...
surfsup Posted December 7, 2007 Author Share Posted December 7, 2007 Great thanks... me being very slow Quote Link to comment https://forums.phpfreaks.com/topic/80632-solved-cheatclock/#findComment-408987 Share on other sites More sharing options...
boushley Posted December 7, 2007 Share Posted December 7, 2007 I'm sure there's probably a more efficient way to do this... but this will get the job done. Quote Link to comment https://forums.phpfreaks.com/topic/80632-solved-cheatclock/#findComment-408996 Share on other sites More sharing options...
PHP_PhREEEk Posted December 7, 2007 Share Posted December 7, 2007 <?php $js_clock1 = date("H, i, s"); ?> <script type="text/javascript"> // Timezone Cheat Clock Setup function run_cheatclock(){ cheatclock(<?php echo $js_clock1; ?>, "timezone1", "ID1"); cheatclock(hour2, minute2, second2, "timezone2", "ID2"); cheatclock(hour3, minute3, second3, "timezone3", "ID3"); } </script> <script type="text/javascript" src="cheatclock.js"></script> <?php // rest of page ?> PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/80632-solved-cheatclock/#findComment-409009 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.