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