我遇到一个问题了,非常基础的,希望大神们能指点一下,不胜感激

scan001 2015-11-19 04:22:32
关于显示时间的,下面的日期显示不出来
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>date对象</title>
<SCRIPT language="javaScript">
function disptime()
{
var now=new Date();
var 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.getYear()+"年"+(now.getMonth()+1)+"月"+now.getDate()+"日</H2>");
document.write("<H2>现在时间:"+now.getHours()+"点"+now.GetMinutes()+"分</H2>");
}
</script>


</head>

<body onload="disptime()">
</body>
</html>
...全文
97 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
scan001 2015-11-19
  • 打赏
  • 举报
回复
引用 6楼天际的海浪 的回复:
[quote=引用 5 楼 scan001 的回复:] 为什么那里要一个+1啊,(now.getMonth()+1)
月份的值是从0开始的[/quote]哦,谢谢呀
scan001 2015-11-19
  • 打赏
  • 举报
回复
引用 4楼转角处灬守候 的回复:
好吧 我找到了 document.write("<H2>今天的日期:"+now.getFullYear()+"年"+(now.getMonth()+1)+"月"+now.getDate()+"日</H2>"); 你把我的替换你的 你的代码中的()有问题
谢谢呀
天际的海浪 2015-11-19
  • 打赏
  • 举报
回复
引用 5 楼 scan001 的回复:
为什么那里要一个+1啊,(now.getMonth()+1)
月份的值是从0开始的
scan001 2015-11-19
  • 打赏
  • 举报
回复
为什么那里要一个+1啊,(now.getMonth()+1)
转角处灬守候 2015-11-19
  • 打赏
  • 举报
回复
好吧 我找到了 document.write("<H2>今天的日期:"+now.getFullYear()+"年"+(now.getMonth()+1)+"月"+now.getDate()+"日</H2>"); 你把我的替换你的 你的代码中的()有问题
天际的海浪 2015-11-19
  • 打赏
  • 举报
回复
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>date对象</title> <SCRIPT language="javaScript"> function disptime() { var now=new Date(); var 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.getYear()+"年"+(now.getMonth()+1)+"月"+now.getDate()+"日</H2>"); document.write("<H2>现在时间:"+now.getHours()+"点"+now.getMinutes()+"分</H2>"); } </script> </head> <body> <script type="text/javascript">disptime()</script> </body> </html>
scan001 2015-11-19
  • 打赏
  • 举报
回复
系统说是语法错误,我跟书上比对了几遍发现没问题呀
转角处灬守候 2015-11-19
  • 打赏
  • 举报
回复
怎么显示不出来呢,年份那个是 now.getFullYear() 这个才对

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧