2014-02-06 153 views
-6

我想把我的小時改爲12小時而不是24小時。約24小時12小時

這是我的代碼:

$(document).ready(function() { 
    var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; 
    var dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; 
    var newDate = new Date(); 
    newDate.setDate(newDate.getDate()); 
    $('#Date').html(dayNames[newDate.getDay()] + " " + newDate.getDate() + ' ' + monthNames[newDate.getMonth()] + ' ' + newDate.getFullYear()); 
    setInterval(function() { 
     var seconds = new Date().getSeconds(); 
     $("#sec").html((seconds < 10 ? "0" : "") + seconds); 
    }, 1000); 
    setInterval(function() { 
     var minutes = new Date().getMinutes(); 
     $("#min").html((minutes < 10 ? "0" : "") + minutes); 
    }, 1000); 
    setInterval(function() { 
     var hours = new Date().getHours(); 
     $("#hours").html((hours < 10 ? "0" : "") + hours); 
    }, 1000); 
}); 
+2

@user這是不幸的,你用你的問題不好的基調。這篇文章聽起來更像是一個需求而不是要求。同時提及你所嘗試的會對你有利。 – gideon

+1

你試過了什麼?在詢問已經在這裏回答了十幾次的問題之前,你是否試圖自己找到答案? – Dropout

+0

對不起先生,如果我ddnt注意到與我的問題相同的其他問題 – user3266160

回答

0

您正在尋找此

newHours = (oldHours) % 12 
if (newHours == 0) { 
    newHours = 12; 
} 
相關問題