DeanWhitehouse Posted May 4, 2008 Share Posted May 4, 2008 I need a clock code that just shows hours and minutes and always updates, e.g you shouldn't need to refresh to show the current time. I was given this code a while ago <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> but this shows seconds, and i don't no how to change it. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 4, 2008 Share Posted May 4, 2008 <script type="text/javascript"> function startTime() { var today=new Date(); var h=today.getHours(); var m=today.getMinutes(); // add a zero in front of numbers<10 m=checkTime(m); document.getElementById('txt').innerHTML=h+":"+m; t=setTimeout('startTime()',500); } function checkTime(i) { if (i<10) { i="0" + i; } return i; } </script> I'm sorry, but I hate lazy people. =/ Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted May 4, 2008 Author Share Posted May 4, 2008 how am i lazy if i don't no how to do something??? as i did try changing it but i changed it wrong. Also this is dislaying on a second line, the code to display it, is this <?php echo gmdate('l, jS F Y');?><div id="txt"></div> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 4, 2008 Share Posted May 4, 2008 All you needed to do was delete the line that said today.getSeconds() and the s variable from the output... Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted May 4, 2008 Author Share Posted May 4, 2008 what i had tried was this <script type="text/javascript"> function startTime() { var today=new Date(); var h=today.getHours(); var m=today.getMinutes(); // add a zero in front of numbers<10 m=checkTime(m); document.getElementById('txt').innerHTML=h+":"+m+"; t=setTimeout('startTime()',500); } function checkTime(i) { if (i<10) { i="0" + i; } return i; } </script> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 4, 2008 Share Posted May 4, 2008 You have an extra " in your script. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted May 4, 2008 Author Share Posted May 4, 2008 anyway, back to my question, it is appearing on a different line, why is this? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 4, 2008 Share Posted May 4, 2008 You want it on the same line? Use <span> instead of <div>. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.