一、创建一个日期对象
语法:new Date();
返回值:不传参的情况下,返回当前的日期时间对象。
说明:如果想根据特定的日期和时间创建日期对象,必须传入表示该日期的毫秒数或者是一组用逗号隔开的表示年月日时分秒的参数。
例1:
var today = new Date();
console.log(today);
结果:
二、获取年月日时分秒的方法
函数 | 功能 |
---|---|
getFullYear() | 返回4位数的年份 |
getMonth() | 返回日期中的月份,返回值为0-11 |
getDate() | 返回月份中的天数 |
getDay() | 返回星期,返回值为0-6 |
getHours() | 返回小时 |
getMinutes() | 返回分 |
getSeconds() | 返回秒 |
getTime() | 返回表示日期的毫秒 |
var weeks = ["日","一","二","三","四","五","六"],
today = new Date(),
year = today.getFullYear(),
month = today.getMonth()+1