| 返回类型 |
构造方法 |
描述 |
| object |
new Date() |
无参构造(当前系统时间) |
| object |
new Date(年,月,日,时,分,秒,毫秒) |
年月日构造(年月必须设置,其它可选) |
| object |
new Date("2023-3-13T00:00:00") |
字符串构造(YYYY-MM-DDTHH:mm:ss.sssZ) |
| object |
new Date(毫秒) |
1970年1月1日之后经过的毫秒数 |
| 返回类型 |
方法 |
描述 |
| int |
getFullYear() |
返回年份 |
| int |
getMonth() |
返回月份(0-11) |
| int |
getDate() |
返回日期(1-31) |
| int |
getHours() |
返回小时(0-23) |
| int |
getMinutes() |
返回分钟(0-59) |
| int |
getSeconds() |
返回秒数(0-59) |
| int |
getMilliseconds() |
返回毫秒(0-999) |
| int |
getDay() |
返回星期(0-6) |
| | | |
| int |
setFullYear(int) |
设置年份 |
| int |
setMonth(int) |
设置月份 |
| int |
setDate(int) |
设置日期 |
| int |
setHours(int) |
设置小时 |
| int |
setMinutes(int) |
设置分钟 |
| int |
setSeconds(int) |
设置秒数 |
| int |
setMilliseconds(int) |
设置毫秒 |
| UTC时间 |
注意:世界时 比 北京时间少8小时 |
| int |
getUTCFullYear() |
世界时,返回年份 |
| int |
getUTCMonth() |
世界时,返回月份(0-11) |
| int |
getUTCDate() |
世界时,返回日期(1-31) |
| int |
getUTCHours() |
世界时,返回小时(0-23) |
| int |
getUTCMinutes() |
世界时,返回分钟(0-59) |
| int |
getUTCSeconds() |
世界时,返回秒数(0-59) |
| int |
getUTCMilliseconds() |
世界时,返回毫秒(0-999) |
| int |
getUTCDay() |
世界时,返回星期(0-6) |
| | | |
| int |
setUTCFullYear(int) |
世界时,设置年份 |
| int |
setUTCMonth(int) |
世界时,设置月份 |
| int |
setUTCDate(int) |
世界时,设置日期 |
| int |
setUTCHours(int) |
世界时,设置小时 |
| int |
setUTCMinutes(int) |
世界时,设置分钟 |
| int |
setUTCSeconds(int) |
世界时,设置秒数 |
| int |
setUTCMilliseconds(int) |
世界时,设置毫秒 |
| 格式化 |
|
| string |
toISOString() |
字符串形式,返回日期时间(ISO格式:YYYY-MM-DDTHH:mm:ss.sssZ) |
| string |
toLocaleDateString() |
字符串形式,返回日期部分(格式:2023/3/12) |
| string |
toLocaleTimeString() |
字符串形式,返回时间部分(格式:22:37:50) |
| string |
toLocaleString() |
字符串形式,返回日期与时间(格式:2023/3/12 22:39:38) |
| 其它 |
|
| int |
getTimezoneOffset() |
返回本地 与 世界时的时差(分钟) |
| int |
getTime() |
返回 到 指定日期的毫秒数(1970年1月1日起) |
| int |
Date.now() |
IE9返回 到 指定日期的毫秒数(1970年1月1日起) |
| int |
parse(string) |
解析,返回 到 指定日期的毫秒数(1970年1月1日起) |
| int |
setTime(int) |
设置指定年月时间(1970年1月1日起毫秒数) |
| string |
toDateString() |
字符串形式,返回日期部分 |
| string |
toJSON() |
IE9字符串形式,返回日期时间(JSON格式:YYYY-MM-DDTHH:mm:ss.sssZ) |
| |
toString() |
将 Date 对象转换为字符串。 |
| |
toTimeString() |
将 Date 对象的时间部分转换为字符串。 |
| |
toUTCString() |
根据世界时,将 Date 对象转换为字符串。 |
| |
UTC() |
根据 UTC 时间,返回自 1970 年 1 月 1 日午夜以来的日期中的毫秒数。 |
| |
valueOf() |
返回 Date 对象的原始值。 |