When you call the constructor of date without passing parameters, the newly created object gets the current date and time by default. var now = new Date ();
- Create a specific date and time object
Date.parse ("String representing the date"); The method receives a string parameter representing the date, which returns the corresponding date format, or Nan if the string cannot represent a date. var nowdate = new Date (Date.parse ("May 25, 2001")); May 25,2001var nowdate = new Date ("may 25,2001"); May 25,2001
var start = Date.now ();
var stop = Date.now (); result = Stop-start; Result results
- Date formatting method, which is to format the date as a string
toDateString () Displays the day, month, day, and year totimestring () in a specific format, displaying the time, minutes, seconds, tolocaledatestring () in a specific format, showing the local date tolocaletimestring () display local time
gettime () and valueof () return the same date, the number of milliseconds returned is settime () & nbsp Set the date in milliseconds, change the entire date getyear () Returns the 2-digit year getfullyear () 4-digit year setfullyear () Set the 4-digit year getmonth () return month setmonth () set month, month must be greater than 0, more than 11 add month getdate () Return Date (1~31) setDate () Set the number of days in the month, if the value passed in exceeds the number of days applied in that month, the month is increased GetDay () return day of the Week gethours () &NBS P number of hours in the return date sethours () Set the number of hours in the date, greater than 23, to increase the month Number of days in getminutES () Returns the number of minutes setminutes () &NBSP ; Set the number of minutes in the date, greater than 59 increase the number of hours
- Gets the current date and time, and formats the date according to YYYY-MM-DD
Gets the current date var nowdate = new Date (); Nowdate.getfullyear (); Nowdate.getmonth () + 1;nowdate.getdate (); nowdate.gethours (); Nowdate.getminutes (); Nowdate.getseconds (); var formatdate = function (nowdate) {var year = nowdate.getfullyear (); var month = Nowdate.getmonth () + 1; Month = Month < 10? "0" + month:month; var date = Nowdate.getdate (); Date = Date < 10? "0" + date:date; Return year + "-" + month + "-" + date;} or var nowstr = Nowdate.format ("Yyyy-mm-dd"), or var nowstr = Nowdate.format ("Yyyy-mm-dd hh:mm:ss"), or var nowstr = Nowdate.format ("yyyy mm month DD Day"), or var nowstr = Nowdate.format ("Yyyy/mm/dd");
JavaScript Red Book note operation date