[英]Format time in hh:mm:ss
如何按時設置格式? 它顯示16:9:2它應該顯示16:09:02
我的代碼:
setInterval(function _timer() {
var time = new Date();
var h = time.getHours();
var m = time.getMinutes();
var s = time.getSeconds();
var fullTime = h + ":" + m + ":" + s;
fullTime.format("hh-MM-ss");// this is not working
$("#time").html(fullTime);
1000
});
你可以嘗試這樣:
var time = new Date(); var h = time.getHours(); var m = time.getMinutes(); var s = time.getSeconds(); alert( ("0" + h).slice(-2) + ":" + ("0" + m).slice(-2) + ":" + ("0" + s).slice(-2));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.