zoukankan      html  css  js  c++  java
  • JavaScript基础17——js的Date对象

     1 <!DOCTYPE html>
     2 <html>
     3     <head>
     4         <meta charset="UTF-8">
     5         <title>js的Date对象</title>
     6         <script type="text/javascript">
     7             var date = new Date();
     8             document.write("当前日期:" + date);
     9             // toLocaleString()方法,根据本地时间格式,把Date对象转换为字符串
    10             document.write("<br />格式化 toLocaleString()方法:" + date.toLocaleString());
    11             // getFullYear()方法,得到当前的四位数年份
    12             document.write("<br />年份 getFullYear():" + date.getFullYear());
    13             // getMonth()方法,得到当前的月份(0-11)
    14             document.write("<br />月份 getMonth():" + (date.getMonth() + 1));
    15             // getDay()方法,得到当前的星期(0-6),外国朋友把星期日作为一周的第一天,所以星期日返回0
    16             document.write("<br />星期 getDay():" + date.getDay());
    17             // getDate()方法,得到当前的日(1-31)
    18             document.write("<br />日 getDate():" + date.getDate());
    19             // getHours()方法,得到当前的小时(0-23)
    20             document.write("<br />小时 getHours():" + date.getHours());
    21             // getMinutes()方法,得到当前的分钟(0-59)
    22             document.write("<br />分钟 getMinutes():" + date.getMinutes());
    23             // getSeconds()方法,得到当前的秒钟(0-59)
    24             document.write("<br />秒钟 getSeconds():" + date.getSeconds());
    25             // getMilliseconds()方法,得到当前的毫秒(0-999)
    26             document.write("<br />毫秒 getMilliseconds():" + date.getMilliseconds());
    27             // getTime()方法,获取1970年1月1日至今的毫秒数
    28             /* 
    29                使用毫秒数处理缓存的效果(没有缓存)
    30                http://www.baidu.com?getTime()的值
    31              */
    32             document.write("<br />1970年1月1日至今的毫秒数 getTime():" + date.getTime());
    33         </script>
    34     </head>
    35     <body>
    36     
    37     </body>
    38 </html>

  • 相关阅读:
    select2插件用法
    MVC htmlAttributes and additionalViewData
    Log4Net 配置详解
    Windows10搭建ASP.NET MVC5 IIS局域网(外网可以访问的)服务器
    网络连接状态指示器(NCSI ,Network Connectivity Status Indicator)
    微软官方开发文档结构WPF
    旋转编码器,无限旋转的音量按钮
    Steam Dota2 安装方法以及一些设置·
    Windows资源管理器打开文件夹卡顿原因及解决办法
    字幕变集合制作工具
  • 原文地址:https://www.cnblogs.com/linyisme/p/5865309.html
Copyright © 2011-2022 走看看