返回JS-日期对象......登陆

JS-日期对象(Date) 学习总结

Mike2018-11-24 23:52:38264
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script type="text/javascript">
    var myday = new Date();
    // 由于国外的计时是从0开始的所以系统的11月是代表是12月!
    //"."的意思是将两个函数进行连接
    //myday 是获取当前的系统时间
    //month 是构造一个数组,解决国外时间规则与国内时间相差一个小时的问题
    // document.write( myday);//获取当前的时间
    // document.write(myday.getFullYear()+"年");//获取年份一定要先调用了new Date获取到当前时间才能获取到年份
    // document.write(myday.getMonth()+"月");
    var month = new Array (12);
        month[0] = '一月';
        month[1] = '二月';
        month[2] = '三月';
        month[3] = '四月';
        month[4] = '五月';
        month[5] = '六月';
        month[6] = '七月';
        month[7] = '八月';
        month[8] = '九月';
        month[9] = '十月';
        month[10] = '十一月';
        month[11] = '十二月';
       document.write("这个月是"+month[myday.getMonth()]);//输出数组中判断当前的月份,如不使用数组来获取当前的月份则无输出的月份比实际会少一个月
       document.write("<br>");
       document.write("今天是星期"+myday.getDay());//getDay  获取当前的星期
       document.write("<br>");
       document.write(myday.getDate());//getDate 获取当前的日期
       document.write("<br>");
       document.write(myday.getHours());//getHours 获取到当前的时钟
       document.write("<br>");
       document.write(myday.getMinutes());//getMinutes 获取当前的分钟
       document.write("<br>");
       document.write(myday.getSeconds());//getSeconds 获取当前秒钟
  </script>
</head>
<body>

</body>
</html>


最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送