Home>

1. Compare date sizes

<script>
function comparedate (d1, d2)
{
 return ((new date (d1.replace (/-/g, "//")))>(new date (d2.replace (/-/g, "//"))));
}
var current_time="2007-02-02 7:30";
var stop_time="2007-01-31 8:30";
console.log (comparedate (current_time, stop_time));
</script>

operation result:

2.Days difference between two dates

<script language="javascript">
<!-
/*
 Date format 2008-01-20
* /
function datediff (sdate1, sdate2) {
 var adate, odate1, odate2, idays;
 adate=sdate1.split ("-");
 odate1=new date (adate [1] + "-" + adate [2] + "-" + adate [0]);
 //Convert to 04-19-2007 format
 adate=sdate2.split ("-");
 odate2=new date (adate [1] + "-" + adate [2] + "-" + adate [0]);
 idays=parseint (math.abs (odate1 -odate2)/1000/60/60/24);//convert the number of milliseconds into days
 return idays;
}
console.log (datediff ("2008-02-25", "2008-03-02"));
//->
</script>

operation result:

  • Previous Java implementation of two threads running case at the same time
  • Next Processing data in JSON format with Python