2011-08-16 96 views
2

我有两个日期格式为dd/mm/yyyy。如何计算javascript/jquery中这两个日期之间的天数。如何计算javascript中两个日期之间的天数

实施例:FOM日期20/06/2000,迄今为止是16/08/2011

+2

可能重复:http://stackoverflow.com/questions/327429/whats-the-best-way-to-calculate-date-difference -in-javascript – LeeR

+2

查看http://stackoverflow.com/questions/1410285/calculating-the-difference-between-two-dates – reporter

+1

@vinothini在询问更多问题之前,您需要接受更多答案。 – Ariel

回答

6

简单的代码

var Date1 = new Date (2008, 7, 25); 
var Date2 = new Date (2009, 0, 12); 
var Days = Math.floor((Date2.getTime() - Date1.getTime())/(1000*60*60*24)); 
3
t1="10/10/2006"; 
t2="15/10/2006"; 

//Total time for one day 
var one_day=1000*60*60*24; //Here we need to split the inputed dates to convert them into standard format for further execution 
var x=t1.split("/");  
var y=t2.split("/"); //date format(Fullyear,month,date) 

var date1=new Date(x[2],(x[1]-1),x[0]); 

// it is not coded by me,but it works correctly,it may be useful to all 

var date2=new Date(y[2],(y[1]-1),y[0]) 
var month1=x[1]-1; 
var month2=y[1]-1; 

//Calculate difference between the two dates, and convert to days 

_Diff=Math.ceil((date2.getTime()-date1.getTime())/(one_day)); 
相关问题