/** 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