如何为时钟设置Am和Pm

时间:2017-04-10 16:41:42

标签: javascript

您好,我想将此时钟设置为在Am和Pm之间切换,即中午12点至凌晨12点。

setInterval(function(){ time();}, 1000)

function time(){
 var dates = new Date();

 var newDates = dates.toDateString();
 // var clock = dates.toLocaleTimeString();
 var seconds = dates.getSeconds();
 var minutes = dates.getMinutes();
 var hours = dates.getHours();
 var stringSeconds= String(seconds);
 var stringMinutes= String(minutes);
 var stringHours= String(hours);
 newDate.textContent = newDates;
 newDivSeconds.textContent =  stringSeconds;
 newDivMinutes.textContent = stringMinutes + '   :' ;
 newDivHours.textContent = stringHours + '   :';

0 个答案:

没有答案