- Date对象是javascript内置的对象,通过它你可以访问计算机系统的时间,Date对象中还提供了多种用于管理、操作的格式化时间与日期的方法。
- JavaScript 中提供了四种不同的方法来创建 Date 对象
var time = new Date();
var time = new Date(milliseconds);
var time = new Date(datestring);
var time = new Date(year, month, date[, hour, minute, second, millisecond]);
- date对象中的方法
getDate()从 Date 对象返回一个月中的某一天 (1 ~ 31)
getDay()从 Date 对象返回一周中的某一天 (0 ~ 6)
getMonth()从 Date 对象返回月份 (0 ~ 11)
getFullYear()从 Date 对象返回四位数字的年份
getYear()使用 getFullYear() 方法代替
getHours()返回 Date 对象的小时 (0 ~ 23)
getMinutes()返回 Date 对象的分钟 (0 ~ 59)
getSeconds()返回 Date 对象的秒数 (0 ~ 59)
getMilliseconds()返回 Date 对象的毫秒(0 ~ 999)
getTime()返回 1970 年 1 月 1 日至今的毫秒数
getTimezoneOffset()返回本地时间与格林威治标准时间 (GMT) 的分钟差
getUTCDate()根据通用时间从 Date 对象返回月中的一天 (1 ~ 31)
getUTCDay()根据通用时间从 Date 对象返回周中的一天 (0 ~ 6)
getUTCMonth()根据通用时间从 Date 对象返回月份 (0 ~ 11)
getUTCFullYear()根据通用时间从 Date 对象返回四位数的年份
getUTCHours()根据通用时间返回 Date 对象的小时 (0 ~ 23)
getUTCMinutes()根据通用时间返回 Date 对象的分钟 (0 ~ 59)
getUTCSeconds()根据通用时间返回 Date 对象的秒钟 (0 ~ 59)
getUTCMilliseconds()根据通用时间返回 Date 对象的毫秒(0 ~ 999)
parse() 返回1970年1月1日午夜到指定日期(字符串)的毫秒数
setDate()设置 Date 对象中月的某一天 (1 ~ 31)
setMonth()设置 Date 对象中月份 (0 ~ 11)
setFullYear()设置 Date 对象中的年份(四位数字)
setYear()使用 setFullYear() 方法代替
setHours()设置 Date 对象中的小时 (0 ~ 23)
setMinutes()设置 Date 对象中的分钟 (0 ~ 59)
setSeconds()设置 Date 对象中的秒钟 (0 ~ 59)
setMilliseconds()设置 Date 对象中的毫秒 (0 ~ 999)
setTime()以毫秒设置 Date 对象