- Date日期对象
(1)Date() 日勤是一个构造函数 必须使用new来调用创建我们的日期对象
var arr = new Array()//创建一个数组对象
var obj = new Object()//创建两年 一个对象实例
(2)使用Date,如果没有参数,返回当前系统的当前时间
var date = new Date()
console.log(date);
(3) //2.参数常用的写法 数字型 2020,04,05 或者是字符串型’2020-4-5 9:9:9’
var date1 = new Date(2020, 4, 5)
console.log(date1);//返回的是五月 不是四月
var date2 = new Date('2020-4-5 9:9:9')
console.log(date2);
- 格式化日期 年月日
var date = new Date()//首先创建一个对象实例
年月日周几的分别写法
console.log(date.getFullYear());//返回当前日期的年 2020
console.log(date.getMonth() + 1);//月份 返回的月份小一个月 记得月份+1呦
console.log(date.getMate());//返回的是几号
console.log(date.getUTCDay);//周一返回的是1,周六返回的是6,但是周日返回的是0
我们写一个 2019年 5月 1日 星期三
var year = date.getFullYear();
var month = date.getMonth() + 1;
var dates = date.getDate();
var arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
var day = date.getDay();
console.log('今天是:' + year + '年' + month + '月' + dates + '日 ' + arr[day]);