Finding days difference in java

后端 未结 5 475
有刺的猬
有刺的猬 2021-01-15 18:53

After consulting a few forums, I ended up using the code below to find the days difference. But, I see a problem with the logic (may be it\'s my over sight?). I see that for

5条回答
  •  天涯浪人
    2021-01-15 19:20

    At least in the current version your code prints correct results

    11 to 11 = 0
    11 to 12 = 1
    11 to 13 = 2
    11 to 14 = 3
    11 to 15 = 4
    11 to 16 = 5
    11 to 17 = 6
    11 to 18 = 7
    11 to 19 = 8
    

    Nevertheless new Date((2013 + 1900), (1 + 1), 11); is incorrect, in fact it is 5813-03-01. It should be new Date((2013 - 1900), (1 - 1), 11); see Date(int year, int month, int day) API

    Parameters:
    year - the year minus 1900.
    month - the month between 0-11.
    date - the day of the month between 1-31.
    

提交回复
热议问题