Days Between Dates Java (homework)

前端 未结 3 2054
醉酒成梦
醉酒成梦 2021-01-22 04:44

This is a couple days off when I run the program. Any advice on what I am doing wrong?

I know there is a simpler way to do it, but for this I\'m trying to show all the a

相关标签:
3条回答
  • 2021-01-22 05:26

    Use java.util.Date: (date1.getTime()-date2.getTime())/(1000*60*60*24).

    0 讨论(0)
  • 2021-01-22 05:27

    Unless this homework or just some self hurting thing you have going can I recommend using the joda time library for all your datetime calculations:

    Time to use joda answer: ~22 minutes

    0 讨论(0)
  • 2021-01-22 05:40

    There's a lot that needs to be said here, but I'd recommend that you start by refactoring this monster into lots of smaller methods that you can test individually. Your code is difficult to read, understand, and debug because of the sheer volume. "Decomposition" is the operative word.

    Your main method should only have driver or test code in it.

    You should have methods like boolean isValid(Date date) and boolean before(Date d1, Date d2) and boolean isLeapYear(int year). Test these individually and start building up to what you want.

    0 讨论(0)
提交回复
热议问题