Skip to content

Instantly share code, notes, and snippets.

@netpi
Created February 27, 2017 05:17
Show Gist options
  • Save netpi/3f31328b1f5c9ad22df445451d577762 to your computer and use it in GitHub Desktop.
Save netpi/3f31328b1f5c9ad22df445451d577762 to your computer and use it in GitHub Desktop.
对比两个日期之间天书
function compareDate(start,end){
if(start==null||start.length==0||end==null||end.length==0){
return 0;
}
var arr=start.split("-");
var starttime=new Date(arr[0],parseInt(arr[1]-1),arr[2]);
var starttimes=starttime.getTime();
var arrs=end.split("-");
var endtime=new Date(arrs[0],parseInt(arrs[1]-1),arrs[2]);
var endtimes=endtime.getTime();
var intervalTime = endtimes-starttimes;//两个日期相差的毫秒数 一天86400000毫秒
var Inter_Days = ((intervalTime).toFixed(2)/86400000)+1;//加1,是让同一天的两个日期返回一天
return Inter_Days;
}
// compareDate('2015-10-24','2017-02-27')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment