date对象获取get

<!DOCTYPE html>
<html lang="en">
<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>date对象</title>
</head>
<body>
    <script>
        today=new Date();//获取今天的日期
        document.write(today+"<hr />");//Thu Dec 12 2019 20:50:03 GMT+0800 (中国标准时间)
        //单独获取年月日时分秒
        var weeks=["","","","","","",""];//因星期返回的是数字,使用数组的方式返回星期的字样
        //索引:weeks[0,   1,   2,  3,   4,   5,   6];
        var year=today.getFullYear(),//返回年
            month=today.getMonth()+1,//返回月…………月返回的数值比正常的月份-1
            date=today.getDate(),//返回日
            week=today.getDay(),//返回星期…………星期返回的是数字从0-6,0表示星期日
            hours=today.getHours(),//返回时
            minutes=today.getMinutes(),//返回分
            seconds=today.getSeconds(),//返回秒
            times=today.getTime();//返回表示日期的毫秒数
        document.write(year+"<hr />");//2019
        document.write(month+"<hr />");//12
        document.write(date+"<hr />");//12
        document.write(week+"<hr />");//4
        document.write(hours+"<hr />");//21
        document.write(minutes+"<hr />");//2
        document.write(seconds+"<hr />");//
        document.write("现在是北京时间:"+year+""+month+""+date+""+hours+""+minutes+""+seconds+"秒 星期"+weeks[week]+"<hr />");
        document.write(times);//表示从1970年1月1日00:00:00开始到现在时间的毫秒数
    </script>
</body>
</html>
原文地址:https://www.cnblogs.com/vinson-blog/p/12031882.html