JS time acquisition function

new Date () // Date first letter must be uppercase

The main initialization is as follows

new Date()

Format with no arguments, return time when using this function

new Date(milliseconds)

Returns the number of milliseconds from January 1, 1970 to date (1ss = 1000ms)

new Date(dateString)

dateString in time format string
wherein dateString can be formatted as follows:
1, "Year Month Day hours: minutes: seconds: ms"
2, "Year Month Day hours: minutes: seconds"
3, "Year Month Day Hour: Minute"
4, "month of May"
5, "May day"
6 "in" // input value is
7, the value // enter "Moon" is 1-12 when the month
8, "date hours: minutes: s: ms "
9," date hour: minute: second "
10," date hour: minute "
11," date "

Notably **
1, in addition to the seventh form, the month can be a value, or may be in English corresponding month.
2, the space character may be some English format instead of
3,0 <months <13; 0 <days <32; 0 <= h <24; 0 <= minutes, seconds <60; 0 <= ms <1000.
**

new Date(year, month, day, hours, minutes, seconds, milliseconds)

The values are initialized Number, and day, hours, minutes, seconds, milliseonds parameter values can be omitted, and the following rules:
**
0 <= month The <=. 11
0 <= Day <= 31 is
0 <= hours <24 =
0 <= minutes <= 59
0 <= seconds The <= 59
milliseconds> = 0 **

Some functions Date () in

getDate () Returns a day (1 to 31) of the month from the Date object.
getDay () Returns the Date object from a day (0-6) of the week.
The getMonth () returns the month (0-11) from the Date object.
the getFullYear () Date object to return a four-digit year.
getHours () Date object hr (0 to 23).
getMinutes () Date object minutes (0 to 59).
the getSeconds () Date object seconds (0 to 59).
the getMilliseconds () Returns the Date object ms (0 to 999).
getTime () returns the number of milliseconds January 1, 1970 to the present.

setDate () Set a day (1 ~ 31) Date object month.
the setMonth () Month Date object set (0 to 11).
the setFullYear () Date object of the year (four digits).
setYear () use the setFullYear () method in place.
setHours () provided h (0 ~ 23) Date object.
the setMinutes () min (0 - 59) of the Date object.
the setSeconds () seconds (0 to 59) of the Date object.
to setMilliseconds () ms (0 to 999) is provided Date object.
the setTime () Date object in milliseconds.

toTimeString () time portion of the Date object to a string.
toDateString () Date the date portion of the object into a string.
toLocaleString () according to the local time format, converts the Date object as a string.
The toLocaleTimeString () according to the local time format, the time portion of the Date object into a string.
The toLocaleDateString () according to the local time format, the date portion of the Date object to a string.
valueOf () returns the original value of the Date object.

Published 24 original articles · won praise 1 · views 2443

Guess you like

Origin blog.csdn.net/qq_35018214/article/details/102873686