The addition and subtraction of JS implementation date
function Dateoperator (date, days, operator) {
Date = Date.replace (/-/g, "/"); Change date format
var nd = new Date (date);
nd = nd.valueof ();
if (operator = = "+") {
nd = nd + days * 24 * 60 * 60 * 1000;
} else if (operator = = "-") {
nd = nd-days * 24 * 60 * 60 * 1000;
} else {
return false;
}
nd = new Date (ND);
var y = nd.getfullyear ();
var m = nd.getmonth () + 1;
var d = nd.getdate ();
if (M <= 9) m = "0" + m;
if (d <= 9) d = "0" + D;
var CDate = y + "-" + M + "-" + D;
return cdate;
How to use
Subtraction
Alert (Dateoperator ("2015-02-28", 1, "-"));
Add
Alert (Dateoperator ("2015-02-28", 1, "+"));
}
Comparison of JS implementation dates
function Datecompare (d1, D2, Operator) {
var D1 = new Date (D1.replace (/-/g, "/"))
var D2 = new Date (D2.replace (/-/g, "/"))
if (Operator = = ">") {
return d1 > D2;
}
if (Operator = = "<") {
return D1 < D2;
}
if (Operator = = "=") {
return D1 = = D2;
}
if (Operator = = "! =") {
return D1! = D2;
}
if (Operator = = ">=") {
return D1 >= D2;
}
if (Operator = = "<=") {
return D1 <= D2;
}
How to use
Alert (Datecompare ("2015-02-28", "2015-02-27", "= ="))
}
Pro-Test effective
Addition and subtraction of JS implementation date, and comparison of dates