当前位置:   article > 正文

js获取当前日期 (年月日 周几)_js获取当前时间年月日 星期几

js获取当前时间年月日 星期几

方法一: js调用
js

  <script type="text/javascript">
      function getCurrentDate() {
          var now = new Date();
          var year = now.getFullYear(); //得到年份
          var month = now.getMonth()+1;//得到月份
          var date = now.getDate();//得到日期
          var day = now.getDay();//得到周几
          var week;
          var arr_week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
          week = arr_week[day];
          var time = "";
          time = "当前时间:" + year + "年" + month + "月" + date + "日" + " " + week;
          document.write(time);
      } 
    </script>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

测试

 <input type="button" id="date_info" value="当前时间" οnclick="geturrentDate();" />

    方法二:在body中直接使用

    <script>
     var now = new Date();
              var year = now.getFullYear(); //得到年份
              var month = now.getMonth();//得到月份
              var date = now.getDate();//得到日期
              var day = now.getDay();//得到周几
              var week;
              var arr_week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
              week = arr_week[day];
              var time = "";
              time = "当前时间:" + year + "年" + month + "月" + date + "日" + " " + week;
              document.write(time);
          } 
     </script>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/292294
    推荐阅读
    相关标签
      

    闽ICP备14008679号