Java is the simplest way to calculate the number of days between two dates and times
•
Java
There is a low way, that is, you change the two times into seconds, divide them by the number of seconds of a day, and then round them up to calculate the number of days. But it's too low.
JDK has advanced APIs. Why should we implement it ourselves? The problem is that we don't know.
So, I'll write a note here to record how JDK 1.8 is done.
The latter method is the key.
LocalDate. toEpochDay()。
Convert the date into epoch days. Epoch is the number of days from 1970-01-01 (ISO). It is the same as that timestamp. The timestamp is the number of seconds.
The article is a little simple, maybe too simple. Just take it as a note.
Thank you for your support for programming tips.
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码