JavaScript Red Book note operation date

Source: Internet
Author: User
Tags local time

    • Create Day Date Object
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
    • Get Start time
var start = Date.now ();
    • Get End time
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
    • Date Component method
 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.