javascript--Date Time

Source: Internet
Author: User


Start reviewing JS today and prepare for the next round of projects:

JavaScript document/////The first part//Creation Date Object//var box=new date ();//Create a Date object//var box=new date (date.parse (' 6/13/2014 '));  Build a Newdate//var box=new Date (DATE.UTC (2011,11)); Build Object//document.write (box); different browsers display different;///Part III: Method of date data (a bit like its own static method)/*//date.parse (): Receives a string parameter that represents a date, and then attempts to return the number of milliseconds of the response based on the string; document.write (   Date.parse (' 6/13/2014 '));  Return to 1402588800000document.write (Date.parse ());  When no incoming or incoming non-standard date format is returned: NAN*///DATE.UTC (): Indicates the number of milliseconds to return the date://document.write (DATE.UTC (2011,11));  1322697600000//document.write (DATE.UTC ()); Not top, generally nan///Part IV: General method//First, as with other types, the date type overrides the toLocaleString (), toString (), and valueof () methods, but the return values of these methods are different from the methods in other types;/*    var box=new Date (2007,13,23,34,42,54);   alert (box);  Sun Feb 10:42:54 gmt+0800document.write (' ToString ' +box.tostring ());   Feb 10:42:54 gmt+0800document.write (' tolocalestring ' +box.tolocalestring ());   2008/2/24 a.m. 10:42:54document.write (' valueof ' +box.valueof ()); Display milliseconds: 1203820974000 *////part Fifth, date formatting method/*//date Type There are also methods that are specifically used to format dates as characters var box=new Date ();d ocument.write (box.todatestring () + "*****************");d Ocument.write (box.totimestring () + "************* ");d Ocument.write (box.tolocaledatestring () +" ***************** ");d Ocument.write (box.tolocaletimestring () +" * ");d Ocument.write (box.toutcstring ());//output: Wed Nov 2014*****************16:57:41 gmt+0800******* 2014/11/26***************** pm 4:57:41*****************wed, 08:57:41 GMT *////Component Method/*//component method, Is the method provided for us to get the various time and date you want separately. It is important to note that these methods have UTC and do not have UTC. The UTC date refers to the date value in the absence of a time zone bias.  var box=new Date ();d ocument.write (box.gettime () + "-------"); Gets the number of milliseconds of the date, and valueof returns the value one to document.write (Box.settime (+) + "-------"); Setting the date in milliseconds will change the entire date document.write (box.getfullyear () + "-------");//get four-bit year document.write (Box.setfullyear (3012) + "-- -----");//sets the four-bit year, which returns the number of milliseconds document.write (Box.getmonth () +"-------");//Gets the number of months, without the specified month, starting from 0 to calculate the document.write ( Box.setmonth (one) + "-------");//Set Month document.write (box.getdate () + "-------");//Get Date document.write (Box.setdate (9) + "-------");//Set Date DocumenT.write (Box.getday () + "-------");//Return day of the week, 0 for Sunday, 6 for Saturday//document.write (box.setday () + "-------");// Set the day of the Week document.write (box.gethours () + "-------");//Return document.write (Box.sethours (3) + "-------"); Set document.write (box.getminutes () + "-------"),//Get Minute document.write (Box.setminutes (+) + "-------");// Set minute document.write (Box.getseconds () + "-------"),//Return description document.write (Box.setseconds (+) + "-------");// Set the Seconds document.write (box.getmilliseconds () + "-------"), or//returns the number of milliseconds document.write (box.setmilliseconds () + "-------"); Set the number of milliseconds document.write (Box.gettimezoneoffset ());//Returns the number of minutes between local event time and UTC time (UTC time is in the absence of time zone bias)//*/// Results:------1416993459539--------------1970-------32882284800100-------0-------32911228800100-------1-------3291192000010 0-------3-------8-------32911902000100-------0-------32911903320100-------0-------32911903353100----------- ---nan-------nan//ps: The above method except getTimezoneOffset (), others have the UTC function, such as setdate () and getdate () get the day of the week, then there is setutcdate () and getUTCDate (). Indicates the coordination time of the elder sister;




javascript--Date Time

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.