月份与日期都不对,只有年份是对的

来源:8-3 计时器setInterval()

guipeng

2017-03-04 22:02

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>定时器</title>

<script type="text/javascript">

  var attime;

  function clock(){

    var time=new Date();

    num=time.getDay();

weekend=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];

    attime=time.getFullYear()+"年"+time.getMonth()+"月"+time.getHours()+":"+time.getMinutes()+":"+time.getSeconds() +weekend[num];

    document.getElementById("clock").value = attime;

  }

  var int=setInterval(clock,1000);

</script>

</head>

<body>

<form>

<input type="text" id="clock" size="50"  />

</form>

</body>

</html>

为什么显示的月份不对,日期也不对只有年份是对的



写回答 关注

4回答

  • gucan
    2017-03-05 12:41:09

    月份加一

  • 路途7
    2017-03-05 00:05:05

    中文与英文有区别哦

  • 慕瓜4890989
    2017-03-04 22:57:53

    那个月份要加一  具体可以看那个章节

  • 慕瓜4890989
    2017-03-04 22:57:05

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>定时器</title>
    <script type="text/javascript">
      var attime;
      function clock(){
        var time=new Date();
        num=time.getDay();
    weekend=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
        attime=time.getFullYear()+"年"+(time.getMonth()+1)+"月"+time.getDate()+"日"+time.getHours()+":"+time.getMinutes()+":"+time.getSeconds() +weekend[num];
        document.getElementById("clock").value = attime;
      }
      var a=setInterval(clock,1000);
    </script>
    </head>
    <body>
    <form>
    <input type="text" id="clock" size="50"  />
    </form>
    </body>
    </html>

JavaScript进阶篇

本课程从如何插入JS代码开始,带您进入网页动态交互世界

468061 学习 · 21891 问题

查看课程

相似问题