开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第31天,点击查看活动详情
1.创建当前(现在)日期对象的实例,不带任何参数
var today = new Date();
2.创建指定时间戳的日期对象实例,参数是时间戳。
时间戳:是指某一个时间距离 1970 年 1 月 1 日 0 时 0 分 0 秒,过去了多少毫秒值(1 秒=1000 毫秒)。
var timer = new Date(10000);
//时间是 1970 年 1 月 1 日 0 时 0 分 10 秒
3.指定一个字符串的日期时间信息,参数是一个日期时间字符串
var timer = new Date(“2015/5/25 10:00:00”);
4.指定多个数值参数
var timer = new Date(2015+100,4,25,10,20,0);
//顺序为:年、月、日、时、分、秒,年、月、日是必须的。
方法:
Date.getDate( ) 返回一个月中的某一天
Date.getDay( ) 返回一周中的某一天
Date.getFullYear( ) 返回 Date 对象的年份字段
Date.getHours( ) 返回 Date 对象的小时字段
Date.getMilliseconds( ) 返回 Date 对象的毫秒字段
Date.getMinutes( ) 返回 Date 对象的分钟字段
Date.getMonth( ) 返回 Date 对象的月份字段
Date.getSeconds( ) 返回 Date 对象的秒字段
Date.getTime( ) 返回 Date 对象的毫秒表示
Date.getTimezoneOffset( ) 判断与 GMT 的时间差
Date.getUTCDate( ) 返回该天是一个月的哪一天(世界时)
Date.getUTCDay( ) 返回该天是星期几(世界时)
Date.getUTCFullYear( ) 返回年份(世界时)
Date.getUTCHours( ) 返回 Date 对象的小时字段(世界时)
Date.getUTCMilliseconds( ) 返回 Date 对象的毫秒字段(世界时)
Date.getUTCMinutes( ) 返回 Date 对象的分钟字段(世界时)
Date.getUTCMonth( ) 返回 Date 对象的月份(世界时)
Date.getUTCSeconds( ) 返回 Date 对象的秒字段(世界时)
Date.getYear( ) 返回 Date 对象的年份字段(世界时)
Date.parse( ) 解析日期/时间字符串
Date.setDate( ) 设置一个月的某一天
Date.setFullYear( ) 设置年份,也可以设置月份和天
Date.setHours( ) 设置 Date 对象的小时字段、分钟字段、秒字段和毫秒字段
Date.setMilliseconds( ) 设置 Date 对象的毫秒字段
Date.setMinutes( ) 设置 Date 对象的分钟字段和秒字段
Date.setMonth( ) 设置 Date 对象的月份字段和天字段
Date.setSeconds( ) 设置 Date 对象的秒字段和毫秒字段
Date.setTime( ) 以毫秒设置 Date 对象
Date.setUTCDate( ) 设置一个月中的某一天(世界时)
Date.setUTCFullYear( ) 设置年份、月份和天(世界时)