/** Determines the difference in days between d and this Date.For example,
* if this Date is 12/15/1997 and d is 12/14/1997, the difference is 1.
* If this Date occurs before d, the result is negative.
* @return the difference in days between d and this date.
*/
public int difference(Date d) {
int NoOfLeapYr_d = d.year/4;
int NoOfLeapYr_this = this.year/4;
int daysofthis = NoOfLeapYr_this + (this.year-1 * 365) + this.dayInYear();
int daysofd = NoOfLeapYr_d + (d.year-1 * 365) + d.dayInYear();
return daysofd - daysofthis;
}
我已经完成了这个逻辑......并且它不工作。它返回了错误的答案。任何人都可以帮助逻辑吗?发现两个给定日期的差异
什么不起作用?你能举一些例子输入,输出和期望的输出吗? – 2011-02-13 14:32:16