javascript - How to make time function update itself? -


when load in browser it'll show time when page loaded, won't update every second. how do this?

var h = date.gethours();   if(h<10) h = "0"+h; var m = date.getminutes(); if(m<10) m = "0"+m; var s = date.getseconds(); if(s<10) s = "0"+s; document.write(h + " : " + m + " : " + s); 

use setinterval:

setinterval(clock, 1000);  function clock() {    var date = new date();    var h = date.gethours();   if(h<10) h = "0"+h;    var m = date.getminutes(); if(m<10) m = "0"+m;    var s = date.getseconds(); if(s<10) s = "0"+s;    document.write(h + " : " + m + " : " + s); } 

although want update html element rather document.write page every second.

http://jsfiddle.net/bqnwj/


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

How to call a javascript function after the page loads with a chrome extension? -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -