line2我跑出538313 而非538320
我也特別再將程式時區改成GMT+8了 答案仍是538313
把測資丟到各日期計算網站上去測
https://www.timeanddate.com/date/durationresult.html?d1=13&m1=12&y1=1186&d2=26&m2=10&y2=2660
https://www.countcalculate.com/calendar/days-between-two-certain-dates
http://www.easysurf.cc/ndate2.htm
以上網站跟我的程式得出同樣的結果538313
https://www.thecalculatorsite.com/misc/days-between-dates.php
https://www.omnicalculator.com/other/day-counter
https://www.calculator.net/date-calculator.html?today=12%2F13%2F1186&ageat=10%2F26%2F2660&calctype=diff&x=48&y=26
https://www.ajdesigner.com/apptime/daysbetweendates.php
https://calendarhome.com/calculate/days-between-2-dates
https://www.topster.net/calendar/zeitrechner.php?styp=zeit&sdatum=1186-12-13&szeit=12%3A00%3A00&typ=zeit&edatum=2660-10-26&ezeit=12%3A00%3A00&subDazu=%2B&jahredazu=0&wochendazu=0&tagedazu=0&zeitdazu=00%3A00%3A00
https://www.days-between-dates.com/
http://www.onlineconversion.com/days_between.htm
以上網站則是538320
https://www.calendar-12.com/days_between_dates
https://planetcalc.com/274/
https://www.calendar-365.com/calculate/period-between-two-dates.html
以上網站不能計算
https://www.mathsisfun.com/measure/calendar-between.html
難用放棄
歷史上曾發生過曆法的修正 ... ( google 一下, 也有說調整多少天 )
本題應該是沒有考慮那些修正,單純以平年閏年來計算天數。
( 站內應該有一題是有考慮修正天數的 )
我用 VB 驗算了一下 , 是 538320 天
Dim d1 As Date = DateSerial(2660, 10, 26)
Dim d2 As Date = DateSerial(1186, 12, 13)
MsgBox(DateDiff(DateInterval.Day, d2, d1)) rem 538320
可否請您說明算法或是上傳一下程式碼呢?因為本人試了多種方法,都無法算出 538313 的天數差距。
甚至考慮進曆法轉換造成的天數差距(11 天),也應為 538309 天。
因為本人算不出來,所以無法幫上您的忙QQ 十分抱歉。
我的code如下:
import java.io.*;
import java.math.*;
import java.util.*;
public class A263_07{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
String[] strArray;
Calendar cal=Calendar.getInstance();
TimeZone tz=TimeZone.getTimeZone("GMT+8");
cal.setTimeZone(tz);
BigDecimal time1,time2;
while(str!=null){
strArray=str.split(" ");
cal.set(Integer.parseInt(strArray[0]),Integer.parseInt(strArray[1])-1,Integer.parseInt(strArray[2]));
time1=new BigDecimal(cal.getTimeInMillis());
str=br.readLine();
strArray=str.split(" ");
cal.set(Integer.parseInt(strArray[0]),Integer.parseInt(strArray[1])-1,Integer.parseInt(strArray[2]));
time2=new BigDecimal(cal.getTimeInMillis());
System.out.println(Math.abs(Integer.parseInt(time1.subtract(time2).divide(new BigDecimal(86400000)).toString())));
str=br.readLine();
}
}
}