<script type="text/jscript">
function clock(){
var d = new Date();
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();
$('#clock').html(", "+h+"<span class='colon'>:</span>"+m+"<span class='colon'>:</span>"+s);
// $('.colon').fadeTo(1000, .2);
setTimeout(clock, 1000);
}
Above is the javascript , which i used to display a clock on my Webapplication.it is working fine but now i want that For any single digit value, the value should be padding 0 before the actual value.
For example
12:15:05,
12:15:15,
12:05:10,
02:05:09
Currently it is showing like this:-
12:15:5,
12:15:15,
12:5:10,
2:5:9
Any help or suggestion that how i achieve this.
Try this
Just add conditional checks on those
h, m and s