Jump to content

Cheat Clock


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.

 

Quote

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

ok - this is how I would do this and you will have to have PHP 5.10+ to get the timezone; unless you manually set it and that is what I am going to do here:

 

<?php

$london = date("g, i, s, \"A\""); // London Time (You Will Not Need To Set A Time Offset For London, Because London's Time Is GMT Time And Most Servers Are Set To GMT Time)

$ny = date("g, i, s, \"A\"", time() - 18000); // New York Time - You Will Have To Set The Time Offset For This Time Zone Based On Your Server's Time - Mine Is -18000 For EST

$tokyo = date("g, i, s, \"A\"", time() + 32400); // Tokyo Time - You Will Have To Set The Time Offset For This Time Zone Based On Your Server's Time - Mine Is +32400 For JST

?>

<script type="text/javascript">
    // Timezone Cheat Clock Setup
    function run_cheatclock(){
        cheatclock(<?php echo "$london"; ?>, "GMT"); // London
        cheatclock(<?php echo "$ny"; ?>, "EST"); // New York
        cheatclock(<?php echo "$tokyo"; ?>, "JST"); // Tokyo
    }
</script>
<script type="text/javascript" src="cheatclock.js"></script>

 

I broke down the PHP for you; but you need to post PHP question the PHP forum and if you have questions about the script I provided you; you can ask me - but if you want to do this script different then the way I provided you; post this question on the PHP forum.

 

Located Here: http://www.phpfreaks.com/forums/index.php/board,1.0.html

 

Good Luck - Hope This Works Out For You ;)

Link to comment
Share on other sites

I just tested my script above and I did not have the JavaScript set exactly right and I also had added a AM/PM variable to my PHP script, where it was not really needed.

 

So Do It This Way (It Works - I Tested It) ;D

 

<html>
<head>
        
<title>Untitled</title>

<style type="text/css">
#times {color:green;font-size:125%;font-weight:bold;font-family:arial}
</style>

<?php

$london = date("G, i, s"); // London Time (You Will Not Need To Set A Time Offset For London, Because London's Time Is GMT Time And Most Servers Are Set To GMT Time)

$ny = date("G, i, s", time() - 18000); // New York Time - You Will Have To Set The Time Offset For This Time Zone Based On Your Server's Time - Mine Is -18000 For EST

$tokyo = date("G, i, s", time() + 32400); // Tokyo Time - You Will Have To Set The Time Offset For This Time Zone Based On Your Server's Time - Mine Is +32400 For JST

?>

<script type="text/javascript">
    // Timezone Cheat Clock Setup
    function run_cheatclock(){
        cheatclock(<?php echo "$london"; ?>, "GMT", "london"); // London
        cheatclock(<?php echo "$ny"; ?>, "EST", "newyork"); // New York
        cheatclock(<?php echo "$tokyo"; ?>, "JST", "tokyo"); // Tokyo
    }
</script>
<script type="text/javascript" src="12-08-2007.js"></script>

</head>
<body>

<div id="times">
London: <span id="london"></span><br>
New York: <span id="newyork"></span><br>
Tokyo: <span id="tokyo"></span>
</div>

</body>
</html>

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.