- What is date?
- Date is a constructor of the dates class and an object that constructs an instance of a Date object.
- There is a now () method that returns the current timestamp (beginning 1970.1.1).
- Date.parse () accepts a date string of a certain format, returning the appropriate timestamp.
- ' 6/30/2017 ', month/day/year
- ' 2016-2-22 ', year-month-day
- ' June12, 2017 ' English month-day year.
DATE.UTC () accepts multiple digits that represent the date, month, and seconds, and returns the timestamp of the response.
- (2015,1,3) represents February 3, 2015.
- How to build a date instance
- Constructor new Date ().
- If the parameter is not passed in, the current date object is returned.
- If the timestamp is passed in, the date object is returned to the corresponding timestamp.
- If more than one number is passed in, the call to the DATE.UTC () method returns a timestamp and then passes the timestamp to the date constructor, returning the response's DateTime object.
- If a string is passed in, the call to the Date.parse () method returns a timestamp and then passes the timestamp to the date constructor, returning the response's DateTime object.
- Some useful methods for the date instance
- Tool Method:
- The date instance provides a number of formatting methods that are perfectly adapted to our everyday use.
- ToString (), the string representation of the returned date
- toLocaleString () that returns the local string representation of the date object.
- ValueOf (), returns the timestamp. It is easy to compare the size of two date objects.
- toTimeString (), returns the string representation of seconds and minutes.
- toLocaleTimeString () ...
- toDateString () that returns a string representation of the date.
- toLocaleDateString (), ...
- Set Date
- SetTime (timestamp), equivalent to the new date (timestamp). GetTime () returns the timestamp.
- setFullYear (), getFullYear ()
- Setmonth (), GetMonth (), 0 represents January.
- SetDate () to set the number of days in the date month. GetDate ()
- GetDay ()
- Sethours (), getHours ()
- Setminutes (), getminutes ().
- Personal view, JS provided date object is still very useful, but it is very cumbersome to use, with the establishment of HTML5 standards, date objects with less and fewer, know to understand.
The Date object in JavaScript