When we need to get the number of milliseconds in the future, the first possible way to think about it is
(new Date ("2014-12-08 12:00:00")). GetTime ()
This will return a number in the method under Chrome.
But in IE the return is a Nan, is because IE thinks YYYY-MM-DD HH:ii:ss is not a reasonable date format
But it can accept the YYYY-MM-DD format.
For universal compatibility, we can decompose the values of each unit for YYYY-MM-DD HH:ii:ss, using the Setxxxx method to get the time you want
var New Date () d.setfullyeard.setdate (8) D.setmonth (one)d.sethours (All) D.setminutes (xx) d.setseconds (00)
D.gettime ()//Returns the number of milliseconds for the 2014-12-08 12:00:00
It must be noted here that setdate must be called before setmonth.
Because in fact setmonth allow two parameters, the first parameter is the month, the second is the date
The second date parameter is not passed, and is set to the date of the day by default
If the new Date () is 31st, and your target month is not the day, D automatically sets its month to the next month with 31st
For example, you call on August 31, the target is one day in September,
// =============== called the wrong order on August 31 d.setmonth (8) d.setdate (1)// The month of D is automatically set to 09 is the actual date of October // because the actual September does not have 31st // set the month and then set the date / / so you get D is actually the October 1 // =============== called the correct order on August 31 d.setdate (1) D.setmonth (8)
Set the setdate first, then set the Setmonth. This ensures that no errors are possible.
JavaScript Date function use need attention place