一、简洁版
1.
<script> var oDate = new Date(); //实例一个时间对象; oDate.getFullYear(); //获取系统的年; oDate.getMonth()+1; //获取系统月份,由于月份是从0开始计算,所以要加1 oDate.getDate(); // 获取系统日, oDate.getHours(); //获取系统时, oDate.getMinutes(); //分 oDate.getSeconds(); //秒 </script>
2.
<p><script>document.write(oDate);</script></p>
效果图:
二、动态显示时间
1、
<script> function showTime() { var now = new Date(); var nowTime = now.toLocaleString(); var date = nowTime.substring(0,10);//截取日期 var time = nowTime.substring(10,20); //截取时间 var week = now.getDay(); //星期 var hour = now.getHours(); //小时 //判断星期几 var weeks = ["日","一","二","三","四","五","六"]; var getWeek = "星期" + weeks[week]; var sc; //判断是AM or PM if(hour >= 0 && hour < 5){ sc = '凌晨'; } else if(hour > 5 && hour <= 7){ sc = '早上'; } else if(hour > 7 && hour <= 11){ sc = '上午'; } else if(hour > 11 && hour <= 13){ sc = '中午'; } else if(hour> 13 && hour <= 18){ sc = '下午'; } else if(hour > 18 && hour <= 23){ sc = '晚上'; } } </script>
2.
<div id="linkweb" ></div>
3.
<script> setInterval("document.getElementById('linkweb').innerHTML=new Date().toLocaleString()+' 星期 '+'日一二三四五六'.charAt(new Date().getDay());",1000); </script>
效果:
文章评论(0)