JS显示时间

来源:互联网 发布:数据挖掘看什么书 编辑:程序博客网 时间:2024/05/01 17:55
<pre name="code" class="html"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script language="javascript">function disptime(){var now = new Date();              //创建一个表示当前日期和时间的对象nowvar hour = now.getHours();         //获取当前时间的小时数if(hour>=0 && hour<=12){document.write("<h2>上午好!</h2>");}if(hour >12 && hour <=18){document.write("<h2>下午好!</h2>");}if(hour>18 && hour <24){document.write("<h2>晚上好!</h2>");}document.write("<h2>今天日期:"+now.getFullYear()+"年"+(now.getMonth()+1)+"月"+now.getDate()+"日</h2>");//由于now.getMonth()方法返回的月份数是0~11,为了与中国的1~12月相对应,所以加1(返回星期几的方法getDay()也是如此)document.write("<h2>现在时间:"+now.getHours()+"点"+now.getMinutes()+"分</h2>");}</script></head><body onload="disptime()"></body></html>




0 0