JS Date对象
2019-06-03 本文已影响0人
Cherry丶小丸子
创建 Date 对象: new Date();
以下四种方法同样可以创建 Date 对象:
var d = new Date();
var d = new Date(milliseconds);
var d = new Date(dateString);
var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
Date 对象属性
Date.constructor // 返回对创建此对象的 Date 函数的引用。
Date.prototype // 使您有能力向对象添加属性和方法。
Date 对象方法
d.getFullYear() // 从 Date 对象以四位数字返回年份。
d.getMonth() // 从 Date 对象返回月份 (0 ~ 11)。
d.getDate() // 从 Date 对象返回一个月中的某一天 (1 ~ 31)。
d.getDay() // 从 Date 对象返回一周中的某一天 (0 ~ 6)。星期日为0
d.getHours() // 返回 Date 对象的小时 (0 ~ 23)。
d.getMinutes() // 返回 Date 对象的分钟 (0 ~ 59)。
d.getSeconds() // 返回 Date 对象的秒数 (0 ~ 59)。
d.getMilliseconds() // 返回 Date 对象的毫秒(0 ~ 999)。
d.getTime() // 返回 1970 年 1 月 1 日至今的毫秒数。
d.parse() // 返回1970年1月1日午夜到指定日期(字符串)的毫秒数。
d.setFullYear() // 设置 Date 对象中的年份(四位数字)。
d.setMonth() // 设置 Date 对象中月份 (0 ~ 11)。
d.setDate() // 设置 Date 对象中月的某一天 (1 ~ 31)。
d.setHours() // 设置 Date 对象中的小时 (0 ~ 23)。
d.setMinutes() // 设置 Date 对象中的分钟 (0 ~ 59)。
d.setSeconds() // 设置 Date 对象中的秒钟 (0 ~ 59)。
d.setMilliseconds() // 设置 Date 对象中的毫秒 (0 ~ 999)。
d.setTime() // setTime() 方法以毫秒设置 Date 对象。
d.toDateString() // 把 Date 对象的日期部分转换为字符串。
d.toISOString() // 使用 ISO 标准返回字符串的日期格式。
d.toJSON() // 以 JSON 数据格式返回日期字符串。
d.toLocaleDateString() // 根据本地时间格式,把 Date 对象的日期部分转换为字符串。
d.toLocaleTimeString() // 根据本地时间格式,把 Date 对象的时间部分转换为字符串。
d.toLocaleString() // 据本地时间格式,把 Date 对象转换为字符串。
d.toString() // 把 Date 对象转换为字符串。
d.toTimeString() // 把 Date 对象的时间部分转换为字符串。
d.valueOf() // 返回 Date 对象的原始值。