The examples in this article describe the way JavaScript asks for a date difference. Share to everyone for your reference, specific as follows:
<script type= "Text/javascript" >
function Daytonow (year, month, date) {
//The idea is to convert two dates to the time stamp, which is the number of milliseconds, Divided by the number of milliseconds per day. How many days apart
//js month is from 0, so month to reduce a
month--;
Past days
var tdate = new Date (year, month, date). GetTime ();
Today
var tnow = new Date (). GetTime ();
var longdate = Math.ceil (tnow-tdate)/(1000 * *));
return longdate;
}
Alert (Daytonow (2009, 4, 5));
</script>
Difference between two date days:
number of days of the date string, before-after, Sdate1-sdate2 function DateDiff (sDate1, SDate2) {//sdate1 and SDate2 are "2002
-12-18 "format var adate, oDate1, ODate2, idays;"
Adate = Sdate1.split ("-");
oDate1 = new Date (adate[0], adate[1]-1, adate[2]);
Adate = Sdate2.split ("-");
ODate2 = new Date (adate[0], adate[1]-1, adate[2]);
Idays = parseint (Math.Abs (odate1-odate2)/1000/60/60/24);
if ((Odate1-odate2) < 0) {return-idays;
return idays; }//Two date string of days of difference, before-after, Sdate1-sdate2 function DateDiff2 (sDate1, SDate2) {//sdate1 and SDate2 are "12/18/2011" format var oDate1, ODate2
, Idays;
oDate1 = new Date (sDate1);
ODate2 = new Date (SDATE2);
var idays = parseint (Math.Abs (odate1-odate2)/1000/60/60/24);
if ((Odate1-odate2) < 0) {return-idays;
return idays; }
More readers interested in JavaScript-related content can view the site topics: "JavaScript Search Algorithm Skills Summary", "JavaScript animation effects and Skills summary", "JavaScript Error and debugging skills summary", " JavaScript data structure and algorithm skills summary, "javascript traversal algorithm and Skills summary" and "JavaScript Mathematical Computing Usage Summary"
I hope this article will help you with JavaScript programming.