Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthormihai
    • CommentTimeNov 14th 2006
     permalink
    I need to show the actual time on a page. Geting the time from the users PC and displaying it is not an option.
    Something like getting the date from the server and a JS that uses that date to start a counter or smth like that.... anyone seen anythng like this ?


    Mike
    • CommentAuthorjcramer
    • CommentTimeNov 15th 2006
     permalink
    You could use javascript to make a call to an external script on a server which would return the exact time on the server with whatever adjustments you want, and then write javascript to output and update data in an html element based on the value(s) that it received. The technology I'm talking about using for making the call to the external script is what we call AJAH, similar to AJAX, only the xml isn't needed and its much easier.

    I'm including a link here to an article my brother wrote on it where he gives his AJAH techniques away...

    http://www.cramertech.com/ajah-a-simple-alternative-to-ajax/

    You'll then need to have a script which is similar to a clock or a timer which will work off of your external data, but you can write something yourself probably, or find the additional help here as you probably know.

    Enjoy..
    • CommentAuthormihai
    • CommentTimeNov 15th 2006
     permalink
    i was thinking of something like this:
    1. javaScript gets date-time from server
    2. it starts internal counter, on the local computer that computes and displays the date-time
    • CommentAuthoreasement
    • CommentTimeNov 15th 2006
     permalink

    Here's what I Use: Get the initial time from the server, and then use javascript to update it. <code> <?

    ///begin system time ///begin system time ///begin system time

    $longOffset = shell_exec('ls -l /etc/localtime');

    if (ereg("GMT+",$longOffset)) { $gmt = split("GMT",$longOffset); } else if (ereg("GMT-",$longOffset)) { $gmt = split("GMT",$longOffset); }

    if (isset($gmt)){ $gmtNum = $gmt[1];

    //fix for the jumpy time
    $gmtVar = trim("Etc/GMT".$gmt[1]);
    date_default_timezone_set($gmtVar);
    

    //end timezone stuff } $timeHH = date("H"); $timeMM = date("i"); $timeSS = date("s"); $dateMM = date("m"); $dateDD = date("d"); $dateYYYY = date("Y");

    ?>

    <script> var timePeriod = 1000;

    function setPeriod(action) {
        if (action == 'pause') {
            timePeriod = 100000;
        } else if (action == 'run') {
            timePeriod = 1000;
            //restart timers
            updateTime(action);
        }
    }
    
    function updateTime(action) {
        clearTimeout(timer);
    
        var timerText = "updateTime('" + action + "')";
        var timer = setTimeout(timerText, timePeriod);
    
        var curHour = parseFloat(document.forms['set_date_time'].hour.value);
        var curMinute = parseFloat(document.forms['set_date_time'].minute.value);
        var curSecond = parseFloat(document.forms['set_date_time'].second.value);
    
        //CHECKING HOURS-MINUTES-SECONDS FOR ROLLOVERS
        if (curSecond >= 59) {
            if (curMinute >= 59) {
                if (curHour >= 23) {
                    curHour = 00;
                    curMinute = 00;
                    curSecond = 00;
                } else {
                    curHour++;
                }
                curMinute = 00;
            } else {
                curMinute++;
            }
            curSecond = 00;
        } else {
            curSecond++;
        }
    
        function addZeros(number){
            if (number <= 9){
                number = "0" + number;
            }
            return(number);
        }
        document.forms['set_date_time'].hour.value = addZeros(curHour);
        document.forms['set_date_time'].minute.value =  addZeros(curMinute);
        document.forms['set_date_time'].second.value = addZeros(curSecond);
    }
    

    </script>

    <div id="time">

    DATE: (mm/dd/yyyy)
    < br /> TIME:

    </div>

    <script language="JavaScript" type="text/javascript">updateTime('start');</script>

    ?> </code>

Add your comments
    Username Password
  • Format comments as (Help)