By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

My Digital Clock sometimes works and sometimes not :(

dmjpro
100+
P: 2,476
Expand|Select|Wrap|Line Numbers
  1. <body onload="setDynColck()">
  2.  
  3. <input type='hidden' id='millsecs' value='Capturing the milliseconds from server side'/>
  4.  
  5. /*******
  6. Some server side coding to manipulate the current time
  7. **************/
  8.  
  9. <td align="center" id="hour1" class="searchbgcolor"><%=First Digit of Hour%></td><td align="center" id="hour2" class="searchbgcolor"><%=Second Digit of Hour%></td>
  10.                     <td align="center" class="searchbgcolor">.</td>
  11.                     <td align="center" id='minute1' class="searchbgcolor"><%=First Digit of Minute%></td><td align="center" id='minute2' class="searchbgcolor"><%=Second Digit of Minute%></td>
  12.  
  13.  
Expand|Select|Wrap|Line Numbers
  1. function setDynColck(){
  2.                 setInterval(showDynClock,60000);
  3.             }
  4.  
  5. function showDynClock(){
  6.                 var img_hour1 = document.getElementById('hour1');
  7.                 var img_hour2 = document.getElementById('hour2');
  8.                 var img_minute1 = document.getElementById('minute1');
  9.                 var img_minute2 = document.getElementById('minute2');
  10.  
  11.                 var milliseconds = document.getElementById('millsecs').value;
  12.                 var current_mill = parseInt(milliseconds,10)+60000;
  13.                 document.getElementById('millsecs').value = current_mill;
  14.                 var current_date = new Date();
  15.                 current_date.setTime(current_mill);
  16.  
  17.                 var hour_str = (current_date.getHours()<10?"0":"")+current_date.getHours();
  18.                 var minute_str = (current_date.getMinutes()<10?"0":"")+current_date.getMinutes();
  19.  
  20. img_hour1.innerHTML = hour_str.charAt(0);
  21.                 img_hour2.innerHTML = hour_str.charAt(1);
  22.                 img_minute1.innerHTML = minute_str.charAt(0);
  23.                 img_minute2.innerHTML = minute_str.charAt(1);
  24.             }
  25.  
I am changing the time at client side at 1 minute interval. Is there any wrong logic?
Feb 11 '09 #1
Share this Question
Share on Google+
4 Replies


acoder
Expert Mod 15k+
P: 16,027
What does "not working" mean? What happens?
Feb 11 '09 #2

dmjpro
100+
P: 2,476
Did you go through the logic fully?
What you think ..is that right ?

Some times the output showing wrong.
Can you test it on your machine using any Server side scripting?
Feb 11 '09 #3

acoder
Expert Mod 15k+
P: 16,027
View the source in the browser and post some sample time data instead, so I can test that.
Feb 11 '09 #4

hsriat
Expert 100+
P: 1,654
@dmjpro
Seems to work without any problem.
Feb 14 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.