创建日期对象,所有关于日期的操作,都需要使用对象来操作
//利用系统提供的构造函数:Date来创建
var date = new Date()
//这个对象是专门用于操作时间日期的,在输出的时候,默认以字符串的形式显示
console.log(date); //输出具体时间
//new Date()获取到的是当前时间的时间日期对象 - 是客户端时间 - 是自己计算机上的时间,如果我们修改自己计算机的时间后,获取到的时间也会发生变化
从时间日期对象中获取具体的时间
var date = new Date()
console.log(date);
//获取年份 - 对象.getFullYear()
var year = date.getFullYear()
console.log(year);
//获取月份 - 对象.getMonth() - 在对象中,使用0~11来描述1~12月
var month = date.getMonth() + 1 //因为获取到的月份会比实际中小1,所以通常加1
console.log(month);
//获取日 - 对象.getDate()
var d = date.getDate() //不能使用date变量表示日
console.log(d);
//获取星期 - 对象.getDay()
var day = date.getDay()
console.log(day);
//获取时 - 对象.getHours()
var hour = date.getHours()
console.log(hour);
//获取分 - 对象.getMinutes()
var minute = date.getMinutes()
console.log(minute);
//获取秒 - 对象.getSeconds()
var second = date.getSeconds()
console.log(second);
//获取毫秒 - 对象.getMilliseconds() 1s === 1000ms
var mill = date.getMilliseconds()
console.log(mill);
//获取时间戳:从1970年1月1日8点0分0秒到现在所走过的毫秒数来描述当前时间的
//语法:对象.getTime()
var time = date.getTime()
console.log(time);