Example code that JavaScript determines the difference between two dates
<!--newszw_hzh_begin-->
Date difference We need to use the same as in PHP, such as 2015-08-30, and then after the conversion to seconds after the two-day number of seconds to subtract after the addition of judgment on it, if the judgment date is more simple than the example at the end of the article to illustrate.
Example 1, date difference function
function Better_time (strdatestart,strdateend) {var strseparator = "-";//Date delimiter var Strdatearraystart; var strdatearrayend; var intday; Strdatearraystart = Strdatestart.split (strseparator); Strdatearrayend = Strdateend.split (strseparator); var strdates = new Date (strdatearraystart[0] + "/" + strdatearraystart[1] + "/" + strdatearraystart[2]); var strdatee = new Date (strdatearrayend[0] + "/" + strdatearrayend[1] + "/" + strdatearrayend[2]); Intday = (strdatee-strdates)/(1000*3600*24); return intday; }
Example 2
Function checktime () { var dateinp=$ ("#dateInp"). Val (); var Day1=date.parse (Dateinp.replace (/-/g, "/")); var nowdate = new date ( ); var datestr = nowdate.getfullyear () + "/" + (Nowdate.getmonth () + 1) + "/" +nowdate.getdate (); var day2= Date.parse (DATESTR); var aparttime=day1-day2; var apartday= parseint (aparttime / (1000 * 60 * 60 * 24)); if ( apartday ==0) { alert ("No Appointment on day"); return false; }else if (apartday < 1 | | apartday > 3) { alert ("Appointment date out of range"); return false; } }
Judge dates Equal
var date1 = new Date ("2013-11-29"); var date2 = new Date ("2013-11-29"); Console.log (date1.gettime () = = Date2.gettime ()); True
Watch out, people, don't write like this!
var date1 = new Date ("2013-11-29"); var date2 = new Date ("2013-11-29"); Console.log (date1 = = Date2); False
This is wrong, because the date is the object after using the new date, so the object cannot be compared as a character.
Reference Source:
Example code that JavaScript determines the difference between two dates
Http://www.lai18.com/content/439055.html
Example code that JavaScript determines the difference between two dates