在JavaScript时钟中的单个字符hh:mm:ss之前添加零 [英] Add zero before single character hh:mm:ss in javascript clock
问题描述
<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);
}
</script>
上面是javascript,我以前在Webapplication上显示时钟,它工作正常,但现在我希望对于任何一位数字值,该值应在实际值之前填充0.例如12:15:05、12:15:15、12:05:10、02:05:09
当前显示如下:-12:15:5、12:15:15、12:5:10、2:5:9
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.
推荐答案
(' " ," + h + " + m + < span class ='colon'>:</span>" + s); //
('#clock').html(", "+h+"<span class='colon'>:</span>"+m+"<span class='colon'>:</span>"+s); //
('.colon').fadeTo(1000,.2 ); setTimeout(clock, 1000 ); } </script>
('.colon').fadeTo(1000, .2); setTimeout(clock, 1000); } </script>
上面是javascript,我以前在Webapplication上显示时钟,它工作正常,但现在我希望对于任何一位数字值,该值应在实际值之前填充0.例如12:15:05、12:15:15、12:05:10、02:05:09
当前显示如下:-12:15:5、12:15:15、12:5:10、2:5:9
我如何实现此目标的任何帮助或建议.
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.
从^ ]
容易...
彼得
Cut''n''paste from here[^]
Easy as...
Peter
这篇关于在JavaScript时钟中的单个字符hh:mm:ss之前添加零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!