The Date type in ECMAScript is built on the Java.unile.Date class in early Java. For this Date type, the number of milliseconds elapsed from midnight on January 1, 1970, has been used to save the date.
In this data storage format, the date of the Date type can be saved accurately until 285616 before or after January 1, 1970
•Date.parse(string)
Accept a string parameter representing the date, and then try to return the number of milliseconds of the corresponding date according to this string. If it cannot be converted, it will return NaN.
•Date.UTC(year, month[, day, hour, min, second, millionsecond])
Return the milliseconds of the corresponding date according to the parameter. Only the first two parameters are required. If other parameters are omitted, all assume to be 0
•Date.now()
Returns the number of milliseconds representing the date and time when this method was called
Inheritance method
•Date.toLocalString()
Return the date and time according to the format that is appropriate to the region set by the browser. The specific format will vary from browser to browser.
•Date.toString()
Usually returns the date and time with time zone information, where time is generally represented by military time (that is, the range of hours is 0-23). The specific format will vary depending on the browser.
•Date.valueOf()
Returns the millisecond representation of the date, which can be used to compare date values
How to format dates
•Date.toDateString()
Displays the day of the week, month, day, and year in implementation-specific format
•Date.toTIMEstring()
Display time, minutes, seconds, and time zones in implementation-specific formats
•Date.toLocaDateString()
Displays the day of the week, month, day and year in a region-specific format
•Date.toLocaTimeString()
Display time, minutes, and seconds in implementation-specific format
•Date.toUTCString()
Complete UTC dates in implementation-specific formats
Date/Time Component Method
The following are methods to directly obtain and set specific parts of date values
•getTime()
Returns the number of milliseconds representing the date, the same value as the value returned by the valueOf() method
•setTime(milliseconds)
Setting the date in milliseconds will change the entire date
•getFullYear()
Get 4-digit year (such as 2007 instead of just 07)
•getUTCFullYear(year)
Returns the 4-digit year of the UTC date
• setFullYear(year)
Set the year of the date. The value of the year passed must be a 4-digit number (such as 2007 instead of just 07)
•setUTCFullYear(year)
Sets the year of the UTC date. The value of the year passed must be a 4-digit number (such as 2007 instead of just 07)
•getMonth()
Returns the month in the date, where 0 means January and 11 means December
•getUTCMonth()
Returns the month in the UTC date, where 0 means January and 11 means December
•setMonth(month)
Set the month of the date, where 0 means January and 11 means December
•setUTCMonth(month)
Set the month of the UTC date, where 0 means January and 11 means December
•getDate()
Returns the number of days in the date month (1 to 31)
•getUTCDate()
Returns the number of days in the UTC date month (1 to 31)
•setDate(Day)
Sets the number of days in the date month. If the value passed in exceeds the number of days that should be in the month, then the month will be increased
•setUTCDate(Day)
Sets the number of days in the UTC date month. If the value passed in exceeds the number of days that should be in the month, then the month will be increased
•getDay()
Returns the day of the week of the day of the week (where 0 represents Sunday, 6 represents 6 of the week)
•getUTCDay()
Returns the day of the week in the UTC date (where 0 represents Sunday, 6 represents 6 of the week)
•getHours()
Returns the number of hours in the date (0 to 23)
•getUTCHours()
Returns the number of hours in the UTC date (0 to 23)
•setHours(time)
Sets the number of hours in the date. The value passed in exceeds 23 increases the number of days in the month
•setUTCHours(time)
Sets the number of hours in the UTC date. The value passed in exceeds 23 increases the number of days in the month
•getMinutes()
Returns the number of minutes in the date (0 to 59)
•getUTCMinutes()
Returns the number of minutes in the UTC date (0 to 59)
•setMinutes(points)
Sets the number of minutes in the date. The value passed in exceeds 59 will increase the number of hours
•setUTCMinutes(points)
Sets the number of minutes in the UTC date. The value passed in exceeds 59 will increase the number of hours
•getSeconds()
Returns the number of seconds in the date (0 to 59)
•getUTCSeconds()
Returns the number of seconds in the UTC date (0 to 59)
•setSeconds(seconds)
Sets the number of seconds in the date. The number of minutes will be increased if the value passed in exceeds 59.
•setUTCSeconds(seconds)
Sets the number of seconds in the UTC date. The number of minutes will be increased if the value passed in exceeds 59.
•getMilliseconds()
Returns the number of milliseconds in the date
•getUTCMilliseconds()
Returns the number of milliseconds in the UTC date
•setMilliseconds(milliseconds)
Set the number of milliseconds in the date
•setUTCMilliseconds(milliseconds)
Set the number of milliseconds in the UTC date
•getTimezoneOffset()
Returns the number of minutes between the local time and the UTC time
The above article briefly discusses the method of time objects in JavaScript is all the content I share with you. I hope it can give you a reference and I hope you can support Wulin.com more.