js基础-内置对象Date

115 阅读1分钟

        /* 返回当前日期和时间 */
        /* Date是一个构造函数 可以通过new来实例化 */
        let today = new Date();
        // console.log(today);

        /* 
            var 日期对象=new Date(参数)
参数格式:MM  DD,YYYY,hh:mm:ss
        */
        /* let oldDate = new Date("10 1,1999,09:35:45"); */
        /* let oldDate = new Date('1999-10-01'); */
        /* getDate() 返回 Date 对象的一个月中的每一天,其值介于1~31之间 多少号 */
        // let hao = oldDate.getDate();

        /* 返回 Date 对象的星期中的每一天,其值介于0~6之间(注:0-周日) */
        // let xinqi = oldDate.getDay();

        /* 返回 Date 对象的小时数,其值介于0~23之间 不传时间默认是8*/
        /* let hours = oldDate.getHours(); */

        /* 返回 Date 对象的分钟数,其值介于0~59之间 */
        /*  let min = oldDate.getMinutes(); */

        /* 返回 Date 对象的秒数,其值介于0~59之间 */
        // let sec = oldDate.getSeconds();

        /* 返回 Date 对象的月份,其值介于0~11之间(注:0-1月份) */
        /*  let mon = today.getMonth();
        console.log(mon+1); */

        /* 返回 Date 对象的年份,其值为4位数 */
        /* let year = today.getFullYear();
        console.log(year); */