The Date object in JavaScript

Source: Internet
Author: User

  1. What is date?
    1. Date is a constructor of the dates class and an object that constructs an instance of a Date object.
    2. There is a now () method that returns the current timestamp (beginning 1970.1.1).
    3. Date.parse () accepts a date string of a certain format, returning the appropriate timestamp.
      1. ' 6/30/2017 ', month/day/year
      2. ' 2016-2-22 ', year-month-day
      3. ' June12, 2017 ' English month-day year.
    4. DATE.UTC () accepts multiple digits that represent the date, month, and seconds, and returns the timestamp of the response.
      1. (2015,1,3) represents February 3, 2015.
  2. How to build a date instance
    1. Constructor new Date ().
      1. If the parameter is not passed in, the current date object is returned.
      2. If the timestamp is passed in, the date object is returned to the corresponding timestamp.
      3. 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.
      4. 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.
  3. Some useful methods for the date instance
    1. Tool Method:
      1. The date instance provides a number of formatting methods that are perfectly adapted to our everyday use.
      2. ToString (), the string representation of the returned date
      3. toLocaleString () that returns the local string representation of the date object.
      4. ValueOf (), returns the timestamp. It is easy to compare the size of two date objects.
      5. toTimeString (), returns the string representation of seconds and minutes.
      6. toLocaleTimeString () ...
      7. toDateString () that returns a string representation of the date.
      8. toLocaleDateString (), ...
    2. Set Date
      1. SetTime (timestamp), equivalent to the new date (timestamp). GetTime () returns the timestamp.
      2. setFullYear (), getFullYear ()
      3. Setmonth (), GetMonth (), 0 represents January.
      4. SetDate () to set the number of days in the date month. GetDate ()
      5. GetDay ()
      6. Sethours (), getHours ()
      7. Setminutes (), getminutes ().
  4. 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

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.