The JavaScript date is subtracted, and then the second date is obtained. In peacetime encounter time plus and minus the probability is relatively large, the following JS function can be completed a specified number of days minus a certain number of days, calculated another date, in many places can be used. You need to look at the function code, which has a usage example, followed by a parameter description.
Example
| The code is as follows |
Copy Code |
var sdate= "2006-06-06"; var edate= "2007-07-07"; var sArr = Sdate.split ("-"); var Earr = Edate.split ("-"); var srdate = new Date (sarr[0], sarr[1], sarr[2]); var erdate = new Date (earr[0], earr[1], earr[2]); var result = (erdate-srdate)/(24*60*60*1000);
|
This result is the number of days between two dates.
Example 2
| The code is as follows |
Copy Code |
<script language=javascript> function cc (DD,DADD) { If you are more considerate, you can add error handling code here var a = new Date (DD) A = A.valueof () A = A-dadd * 24 * 60 * 60 * 1000 A = new Date (a) Alert (a.getfullyear () + "year" + (A.getmonth () + 1) + "month" + a.getdate () + "Day") } Call Method: CC ("10/11/2016", 2) </script> |
Parameter description: This function involves two parameters: DD: the date to be calculated; Dadd: The number of days to subtract, such as 2 days, 3 days.