Date~JS

Date对象是基于1970年1月1日(世界标准时间)起的毫秒数。
以常规函数调用它(即不加 new 操作符)将会返回一个字符串,而不是一个日期对象。另外,不像其他JavaScript 类型,Date 对象没有字面量格式。
如果数值大于合理范围时(如月份为13或者分钟数为70),相邻的数值会被调整。比如 new Date(2013, 13, 1)等于new Date(2014, 1, 1),它们都表示日期2014-02-01(注意月份是从0开始的)。其他数值也是类似,new Date(2013, 2, 1, 0, 70)等于new Date(2013, 2, 1, 1, 10),都表示时间2013-03-01T01:10:00。
当Date作为构造函数调用并传入多个参数时,所定义参数代表的是当地时间。
如果没有输入任何参数,则Date的构造器会依据系统设置的当前时间来创建一个Date对象。
如果提供了至少两个参数,其余的参数均会默认设置为1(如果没有提供day参数)或者0。

var today = new Date();
var today = new Date(1453094034000); // by timestamp(accurate to the millimeter)
var birthday = new Date('December 17, 1995 03:24:00');
var birthday = new Date('1995-12-17T03:24:00');
var birthday = new Date(1995, 11, 17);
var birthday = new Date(1995, 11, 17, 3, 24, 0);
//new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);

Date.prototype

允许为 Date 实例对象添加属性。

Date.length

Date.length 的值是 7。这是该构造函数可接受的参数个数。

Date.now()

返回自 1970-1-1 00:00:00 UTC (世界标准时间)至今所经过的毫秒数。

Date.parse()

解析一个表示日期的字符串,并返回从 1970-1-1 00:00:00 所经过的毫秒数。

Date.UTC()

接受和构造函数最长形式的参数相同的参数(从2到7),并返回从 1970-01-01 00:00:00 UTC 开始所经过的毫秒数。

Date.prototype.getDate()

根据本地时间返回指定日期对象的月份中的第几天(1-31)。

Date.prototype.getDay()

根据本地时间返回指定日期对象的星期中的第几天(0-6)。

Date.prototype.getFullYear()

根据本地时间返回指定日期对象的年份(四位数年份时返回四位数字)。

Date.prototype.getHours()

根据本地时间返回指定日期对象的小时(0-23)。

Date.prototype.getMilliseconds()

根据本地时间返回指定日期对象的微秒(0-999)。

Date.prototype.getMinutes()

根据本地时间返回指定日期对象的分钟(0-59)。

Date.prototype.getMonth()

根据本地时间返回指定日期对象的月份(0-11)。

Date.prototype.getSeconds()

根据本地时间返回指定日期对象的秒数(0-59)。

Date.prototype.getTime()

返回从1970-1-1 00:00:00 UTC(协调世界时)到该日期经过的毫秒数,对于1970-1-1 00:00:00 UTC之前的时间返回负值。

Date.prototype.getTimezoneOffset()

返回当前时区的时区偏移。

Date.prototype.getUTCDate()

Returns the day (date) of the month (1-31) in the specified date according to universal time.

Date.prototype.getUTCDay()

Returns the day of the week (0-6) in the specified date according to universal time.

Date.prototype.getUTCFullYear()

Returns the year (4 digits for 4-digit years) in the specified date according to universal time.

Date.prototype.getUTCHours()

Returns the hours (0-23) in the specified date according to universal time.

Date.prototype.getUTCMilliseconds()

Returns the milliseconds (0-999) in the specified date according to universal time.

Date.prototype.getUTCMinutes()

Returns the minutes (0-59) in the specified date according to universal time.

Date.prototype.getUTCMonth()

Returns the month (0-11) in the specified date according to universal time.

Date.prototype.getUTCSeconds()

Returns the seconds (0-59) in the specified date according to universal time.

Date.prototype.setDate()

根据本地时间为指定的日期对象设置月份中的第几天。

Date.prototype.setFullYear()

根据本地时间为指定日期对象设置完整年份(四位数年份是四个数字)。

Date.prototype.setHours()

根据本地时间为指定日期对象设置小时数。

Date.prototype.setMilliseconds()

根据本地时间为指定日期对象设置毫秒数。

Date.prototype.setMinutes()

根据本地时间为指定日期对象设置分钟数。

Date.prototype.setMonth()

根据本地时间为指定日期对象设置月份。

Date.prototype.setSeconds()

根据本地时间为指定日期对象设置秒数。

Date.prototype.setTime()

通过指定从 1970-1-1 00:00:00 UTC 开始经过的毫秒数来设置日期对象的时间,对于早于 1970-1-1 00:00:00 UTC的时间可使用负值。

Date.prototype.setUTCDate()

根据世界时设置 Date 对象中月份的一天 (1 ~ 31)。

Date.prototype.setUTCFullYear()

根据世界时设置 Date 对象中的年份(四位数字)。

Date.prototype.setUTCHours()

根据世界时设置 Date 对象中的小时 (0 ~ 23)。

Date.prototype.setUTCMilliseconds()

根据世界时设置 Date 对象中的毫秒 (0 ~ 999)。

Date.prototype.setUTCMinutes()

根据世界时设置 Date 对象中的分钟 (0 ~ 59)。

Date.prototype.setUTCMonth()

根据世界时设置 Date 对象中的月份 (0 ~ 11)。

Date.prototype.setUTCSeconds()

根据世界时设置 Date 对象中的秒钟 (0 ~ 59)。

Date.prototype.toDateString()

以人类易读(human-readable)的形式返回该日期对象日期部分的字符串。

Date.prototype.toISOString()

把一个日期转换为符合 ISO 8601 扩展格式的字符串。

Date.prototype.toJSON()

使用 toISOString() 返回一个表示该日期的字符串。为了在 JSON.stringify() 方法中使用。

Date.prototype.toLocaleDateString()

返回一个表示该日期对象日期部分的字符串,该字符串格式与系统设置的地区关联(locality sensitive)。

Date.prototype.toLocaleString()

返回一个表示该日期对象的字符串,该字符串与系统设置的地区关联(locality sensitive)。覆盖了 Object.prototype.toLocaleString() 方法。

Date.prototype.toLocaleTimeString()

返回一个表示该日期对象时间部分的字符串,该字符串格式与系统设置的地区关联(locality sensitive)。

Date.prototype.toString()

返回一个表示该日期对象的字符串。覆盖了Object.prototype.toString() 方法。

Date.prototype.toTimeString()

以人类易读格式返回日期对象时间部分的字符串。

Date.prototype.toUTCString()

把一个日期对象转换为一个以UTC时区计时的字符串。

Date.prototype.valueOf()

返回一个日期对象的原始值。覆盖了 Object.prototype.valueOf() 方法。

猜你喜欢

转载自www.cnblogs.com/qq3279338858/p/8932305.html