Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2003
    Location
    ireland
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to: time date etc...

    i have been having trouble in the past trying to make pges that use the date. Say for instance, count down to christmas in seconds hours and days.

    could you tell me how to get the date into a var and then take that away from the date of christmas.

    and would i need to put the seconds hours days months and years in seperate vars.


    thanks
    hello says narf
    and narf says hello

  • #2
    Regular Coder COBOLdinosaur's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Try this:

    <html>
    <head><title>none</title>
    <script type="text/javascript">
    <!--
    var xmas= new Date(2003,11,25,0,0,0);
    function setCountdown() {
    var now= new Date();
    var diff=xmas.valueOf()-now.valueOf();
    diff=parseInt(diff/1000);
    days=parseInt(diff/86400);
    diff-=days*86400;
    hours=parseInt(diff/3600);
    diff-=hours*3600;
    minutes=parseInt(diff/60);
    diff-=minutes*60;
    str=days+" days "+hours+" hours "+minutes+" minutes and "+diff+" seconds to Christmas";
    document.getElementById('countdown').innerHTML=str;
    setTimeout('setCountdown()',1000);
    }
    //-->
    </script>
    </head>
    <body onLoad="setCountdown()">
    <div id="countdown" style="width:400px;border:4px double blue;text-align:center;">
    &nbsp;</div>
    </body>
    </html>


    You can put each part in its own var if you want and you can put it in to a form field, or just about any element or control that will accept a string.
    100% standards compliant code is 100% correct 100% of the time.
    one of my toys from my repository and perhaps some help getting help

    Cd&


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •