Jump to content

[SOLVED] CheatClock


surfsup

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.