date对象

一.代码示例 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>时间</title>
</head>
<body>
    <script type="text/javascript">
    //获取当前时间
    var date = new Date();
    document.write(date);
    //转换为字符串
    document.write("<hr/>");
    document.write(date.toLocaleString());
    //得到当前的年份
    document.write("<hr/>");
    document.write("year :"+date.getFullYear());
    //获取当前的月份
    //返回的是0~11月,想要得到准确的值必须加一
    document.write("<hr/>");
    var date1 = date.getMonth()+1;
    document.write("month :"+date1);
    //获取当前星期
    //外国将星期日作为一周的开始,返回的是0~6
    document.write("<hr/>");
    document.write("week:"+date.getDay());
    //获取当前的天
    document.write("<hr/>");
    document.write("day:"+date.getDate());
    //获取当前小时
    document.write("<hr/>");
    document.write("hours:"+date.getHours());
    //获取当前分钟
    document.write("<hr/>");
    document.write("Minutes:"+date.getMinutes());
    //获取当前秒
    document.write("<hr/>");
    document.write("Seconds:"+date.getSeconds());
    //获取从1970 1 1到至今的毫秒数
    document.write("<hr/>");
    document.write("Time:"+date.getTime());
    </script>
</body>
</html>

 

posted @ 2019-02-11 11:32  静心*尽力  阅读(94)  评论(0编辑  收藏  举报