HTML5代碼
<div id="time"> <span id="hour"></span> <span id="data"></span></div>
CSS代碼
#time{ float: right; width: auto; padding:0 50px; border-left: 2px solid rgba(255,255,255,.3); height: 54px; margin-top: 13px; margin-left: 40px; color:#fff; cursor: default; text-align: center;}#hour{ display: block; width: auto; font-size: 22px; height: 34px; line-height: 34px; color:#fff; cursor: default;}#data{ display: block; width: auto; font-size: 10px; height:20px; line-height: 20px; color:#fff; cursor: default;}
jquery代碼
/*時間計數器*/function p(s) { return s < 10 ? '0' + s: s;}function nowtime() { var myDate = new Date(); var year = myDate.getFullYear(); //擷取當前年 var month = myDate.getMonth()+1; //擷取當前月 var date = myDate.getDate(); //擷取當前日 var h = myDate.getHours(); //擷取當前小時數(0-23) var m = myDate.getMinutes(); //擷取當前分鐘數(0-59) var s = myDate.getSeconds(); var data = year+ '-' + p(month)+ "-"+ p(date); var hour = p(h)+ ':'+ p(m); $("#data").html(data); $("#hour").html(hour);}nowtime();setInterval(nowtime,1000);