4. Entry 4: javascript date object

Source: Internet
Author: User

Date objects are not commonly used in js. They can be replaced by strings. However, date objects are often used in date comparison and sorting. The following describes common usage of date objects:
<Script type = "text/javascript"> var d = new Date (); // instantiate a Date object // The following is the document for obtaining the Date, month, day, hour, minute, second, millisecond value. write (d. getFullYear (); document. write (d. getMonth (); document. write (d. getDate (); document. write (d. getHours (); document. write (d. getMinutes (); document. write (d. getSeconds (); document. write (d. getMilliseconds (); // set the value of var d1 = new Date (); d1.setFullYear (1980); d1.setMonth (10); d1.setDate (10 ); d1.setHours (9); d1.setMinutes (10); d1.setSeconds (10); d1.setMilliseconds (100); // compare the size of two dates. The result is truedocument. write (d> d1); </script>

The following is a date utility:

// Function dtoS (d) {var s = ""; s + = (d. getFullYear () + "year"); s + = (d. getMonth () + 1) + "month"); s + = (d. getDate () + "day"); s + = ("" + d. getHours () + ":"); s + = ("" + d. getMinutes () + ":"); s + = ("" + d. getSeconds (); return s;} var d = new Date (); var s = dtoS (d); // The result is September 22, 2013.

This article from the "Yu yu" blog, please be sure to keep this source http://johnyu.blog.51cto.com/7838287/1299960

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.