所以我在网上找到了javascript,php和ajax的脚本,所以时间刷新每一秒并更新。但我有两位数的问题。就像6/8/2017 - 19:8:54。有人可以帮帮我吗?
<script type="text/javascript">
function display_c(){
var refresh=1000; // Refresh rate in milli seconds
mytime =setTimeout('display_ct()',refresh)
}
function display_ct() {
var strcount
var x = new Date()
var x1=x.getDate() + "/" + x.getMonth() + "/" + x.getYear();
x1 = x1 + " - " + x.getHours( )+ ":" + x.getMinutes() + ":" +
x.getSeconds();
document.getElementById('ct').innerHTML = x1;
tt=display_c();
}
</script>
答案 0 :(得分:1)
您可以使用以下内容:
var x1 = ('0' + x.getDate()).slice(-2) + '/'
+ ('0' + (x.getMonth()+1)).slice(-2) + '/'
+ x.getFullYear() + '-'
+ ('0' + x.getHours()).slice(-2) + ':'
+ ('0' + x.getMinutes()).slice(-2) + ':'
+ ('0' + x.getSeconds()).slice(-2);