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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Location
    Belgium
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    JavaScript clock, adjustable depending on user input

    Hello, everyone. I am currently on my way to create my own site, but I would like to create a ticking clock with javascript.
    My only problem is this:
    In the registration form for the users, I let them select in what timezone they are, so later on when they log in they would see a clock for that timezone.
    How do I make this?
    Help me please

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    One option is to use the javascript Date object to get the current hours, minutes and seconds from the users pc at 1 second intervals using setInterval() and display it.

  • #3
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Do you already have a ticking clock
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #4
    New to the CF scene
    Join Date
    May 2011
    Location
    Belgium
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you for the quick replies!

    Yes, andrew, I do indeed have a script for a ticking clock (I'll show it in a second), but the fact is that I gave those <option><select></select></option> a few values that I inserted into MySQL database, and now I'd basically get those things out of my database (I know how to get them out), but also use those values (e.g. -6) to adapt my clock.

    My ticking clock script:
    <script type="text/javascript">
    function startTime()
    {
    var today=new Date();
    var h=today.getHours();
    var m=today.getMinutes();
    var s=today.getSeconds();
    // add a zero in front of numbers<10
    m=checkTime(m);
    s=checkTime(s);
    document.getElementById('txt').innerHTML=h+":"+m+":"+s;
    t=setTimeout('startTime()',500);
    }

    function checkTime(i)
    {
    if (i<10)
    {
    i="0" + i;
    }
    return i;
    }
    </script>
    </head>

    <body onload="startTime()">
    <div id="txt"></div>
    </body>

  • #5
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Something like this:
    Code:
    var today = new Date();
    var adjDate = new Date(today.getTime());
    adjDate.setHours(adjDate.getHours()+h);   // where h is -6, for example
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    Athro (05-04-2011)

  • #6
    New to the CF scene
    Join Date
    May 2011
    Location
    Belgium
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    So I just replace that h by for example -6 or +6?
    Ahh, thanks! This really helped me ^.^

  • #7
    New to the CF scene
    Join Date
    May 2011
    Location
    Belgium
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Oh, one more thing, though, is there a special thing for summertime etc?


  •  

    Posting Permissions

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