Get the current time new Date ()
myDate = var new new a Date (); // millisecond, 1970.1.1 start
myDate. getYear (); // Get the current year (2)
myDate. getFullYear (); // get the full year (4, 1970-? ???)
. myDate getMonth (); // get the current month (0-11,0 on behalf of January) so // get the current month is myDate.getMonth () + 1;
. myDate getDate (); // get the current day (1-31)
. myDate getDay (); // get the current week X (0-6,0 for Sunday)
myDate. getTime (); // get the current time (the number of milliseconds from the start 1970.1.1)
myDate. getHours (); // Get the current hour (0-23)
myDate. getMinutes (); // get the current number (0-59) minutes
myDate. the getSeconds (); // get the current number of seconds (0-59)
myDate .the getMilliseconds (); // get the current milliseconds (0-999)
myDate. The toLocaleDateString (); // get the current date
var MyTime = myDate. The toLocaleTimeString (); // get the current time
myDate. toLocaleString (); // get the date and time
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
JS obtain the current time stamp method, current millisecond acquisition time stamp has the following three methods:
var timestamp = Date.parse (new Date ()); Results: // 1280977330000 not recommended; 000 milliseconds changed display
var timestamp = (new Date ()) valueOf (); result: // 1280977330748 recommendation;
var timestamp = new Date () getTime (); result: // 1280977330748 recommendation;
js Separate call new Date ();
Such a display format Mar 31 10:10:43 UTC + 0800 2012
However, with new Date () participate in the calculation it will be automatically converted to a number of milliseconds from the start 1970.1.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
String date conversion date objects
var strTime = "2015-09-26"; // date format string
var date = new Date (Date.parse ( strTime.replace (// g, "/"))); // converted to the Data () ;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new Date (); // may be an integer parameter; may be a string; however, must be properly formatted
new Date (2009,1,1); // correct
new Date ( "2009/1/1"); // correct
new Date ( "2009-1-1"); // error
new Date (year, month, date , hrs, min, sec) by the given parameter to create a target date
Parameters:
year values: -1900 year to be set. For example, the year 1997 is to be set to be 97 year value, i.e. the result of 1997-1900. Date Year so settable minimum 1900;
month The value range is 0 to 11, 0 representing January, 11 table represents Dec;
DATE value range 31 is between ~. 1;
HRS in the range of 0 ~ 23. From between midnight to 1:00 hrs = 0, from noon to 1:00 p.m. inter = 12 is HRS;
min sec and range of between 0 to 59.
Example Date day = new Date (11,3,4) ;
time // day is from: 04-Apr-11 12:00:00 AM
Further, it may also give an incorrect parameter.
Example Set the time for the February 30, 1910, it will be interpreted as 2 March.
Day = new new DATE DATE (10,1,30,10,12,34);
System.out.println ( "Day's DATE IS:" + Day);
// print results: Day's date is: Web Mar 02 10: 13:34 GMT + 08: 00 1910
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~