954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Display a clock

Hi all,
I do not know where to put these Thread , so I am hoping that you will answer me here .

http://www.w3schools.com/js/tryit.asp?filename=tryjs_timing_clock

I do not understand why these code display clock .


Thank you for your effort of reading .

kv79
Posting Whiz in Training
292 posts since Nov 2007
Reputation Points: 30
Solved Threads: 7
 

hi

var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();

All this is doing is pulling the date from your local computer (little clock in the bottom right corner (on xp). And storing the hours, mins and seconds in variables.

the rest of the script is a bit usless and just makes it look complicated. All it does is add 0's and stuff.

This is quite simple javascript, so if you are just hopping, trying to grasp the language, i would suggest to start at the beggining and go slowly making sure you understand peices before moving on.

Reece

Designer_101
Posting Whiz
314 posts since Jul 2007
Reputation Points: 12
Solved Threads: 16
 

But this code is not give me a null if number in lower that 10 . It was a 2 hour when i learn these and i did not see any null .

kv79
Posting Whiz in Training
292 posts since Nov 2007
Reputation Points: 30
Solved Threads: 7
 

all thats doing is adding a 0, if the number is less than 10??
I dont understand what your asking? :S
Reece

Designer_101
Posting Whiz
314 posts since Jul 2007
Reputation Points: 12
Solved Threads: 16
 

Test it with your clock . It is all i want to say is that not working .

kv79
Posting Whiz in Training
292 posts since Nov 2007
Reputation Points: 30
Solved Threads: 7
 

its working fine for me
what browser are you using? there may be a problem, for instance
Javascript could be turned of
Your Clock is covered by a firewall (highly unlikely)

Designer_101
Posting Whiz
314 posts since Jul 2007
Reputation Points: 12
Solved Threads: 16
 

Java script is on and i am using a firefox 2.0.0.12

kv79
Posting Whiz in Training
292 posts since Nov 2007
Reputation Points: 30
Solved Threads: 7
 

Hey i have a question,I have an apache tomcat server with a html page that has a clock.And if other person access the same html page in his system,the clock shows the time that his system has.So consider my server clock is correct and the other persons clock is incorrect.How can i make the time in html page to be correct who ever may open the html page(i want my server time to be global whoever open this particular html page in his system regardless of any time that he has)?I hope you understood my question

rubincroy
Newbie Poster
1 post since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

Okay - first, javascript reads the time off the system it's on - it's not reading time off the server at all. A work around is to detect how far off the time on system is from GMT then add back a correction for how far off of GMT the server is. But this isn't going to do anything about his system clock being off by minutes from yours.

I'm sure there is a way to read server time, but it won't be a javascript solution.

Dandello
Posting Whiz in Training
263 posts since May 2010
Reputation Points: 28
Solved Threads: 23
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You