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. Link to comment https://forums.phpfreaks.com/topic/104069-solved-clock-code-dynamic-updating/ 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. =/ Link to comment https://forums.phpfreaks.com/topic/104069-solved-clock-code-dynamic-updating/#findComment-532715 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> Link to comment https://forums.phpfreaks.com/topic/104069-solved-clock-code-dynamic-updating/#findComment-532723 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... Link to comment https://forums.phpfreaks.com/topic/104069-solved-clock-code-dynamic-updating/#findComment-532735 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> Link to comment https://forums.phpfreaks.com/topic/104069-solved-clock-code-dynamic-updating/#findComment-532740 Share on other sites More sharing options...
DarkWater Posted May 4, 2008 Share Posted May 4, 2008 You have an extra " in your script. Link to comment https://forums.phpfreaks.com/topic/104069-solved-clock-code-dynamic-updating/#findComment-532744 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? Link to comment https://forums.phpfreaks.com/topic/104069-solved-clock-code-dynamic-updating/#findComment-532746 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>. Link to comment https://forums.phpfreaks.com/topic/104069-solved-clock-code-dynamic-updating/#findComment-532749 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.