JS时间对象操作以及时间格式化
First Post:
Last Update:
Last Update:
JS时间对象
取当前时间
1 |
|
取年、月、日
1 |
|
其他方法 get
getTime()
:返回从 1970 年 1 月 1 日至今的毫秒数。getDay()
: 返回当前是星期几,返回值范围 (0-6)。getHours()
: 返回时,返回值范围 (0-23)。getMinutes()
:返回分,返回值范围 (0-59)。getSeconds()
:返回秒,返回值范围 (0-59)。getMilliseconds()
:返回毫秒,返回值范围 (0-999)。
其他方法 set
setFullYear()
:设置 Date 对象中的年份(四位数字)。setMonth()
:设置 Date 对象中的月份,取值范围 (0 ~ 11)。setDate()
:设置 Date 对象中月的某一天,取值范围 (1 ~ 31)。setHours()
:设置 Date 对象中的时,取值范围 (0 ~ 23)。setMinutes()
:设置 Date 对象中的分,取值范围 (0 ~ 59)。setSeconds()
:设置 Date 对象中的秒,取值范围 (0 ~ 59)。setMilliseconds()
:设置 Date 对象中的毫秒,取值范围 (0 ~ 999)。setTime()
:以毫秒设置 Date 对象。
格式化时间格式常用方法
1 |
|