1.显示结果;
2,样式;
<style>
.top_time{ float:right; width:240px; color:#0026ff;text-shadow:3px 3px 5px #6388c2; font-size:16px; padding-top:10px;}
.top_time #time{ font-size:48px; float:left; height:50px; line-height:50px; padding-right:15px;}
.top_time #date{ padding-top:10px;}
</style>
3,js
1 <div class="top_time top_time_r"> 2 <div id="time"></div> 3 <div id="date"></div> 4 <div id="week"></div> 5 <script> 6 setInterval("setDate()", 1000); 7 function setDate() { 8 var myDate = new Date(); 9 var hours = myDate.getHours(); 10 var date = myDate.getMinutes(); 11 var month = myDate.getMonth(); 12 var date1 = myDate.getDate(); 13 if (myDate.getHours() < 10) 14 hours = "0" + myDate.getHours(); 15 if (myDate.getMinutes() < 10) 16 date = "0" + myDate.getMinutes(); 17 if (myDate.getMonth() < 9) { 18 // alert(myDate.getMonth()); 19 month = "0" + (parseInt(myDate.getMonth()) + 1); 20 } else { 21 month =parseInt(myDate.getMonth()) + 1; 22 } 23 24 if (myDate.getDate() < 10) 25 date1 = "0" + myDate.getDate(); 26 document.getElementById("time").innerHTML = hours + ":" + date; 27 document.getElementById("date").innerHTML = month + "-" + date1; 28 document.getElementById("week").innerHTML = ‘星期‘ + ‘日一二三四五六‘.charAt(new Date().getDay()); 29 } 30 </script> 31 </div>
时间: 2024-10-07 11:56:41