import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
class Solution {
public int daysBetweenDates(String date1, String date2) {
if (date1 == null || date1.length() == 0 || date2 == null || date2.length() == 0) {
return 0;
}
LocalDate dateBefore = LocalDate.parse(date1);
LocalDate dateAfter = LocalDate.parse(date2);
return (int) Math.abs(ChronoUnit.DAYS.between(dateBefore, dateAfter));
}
}
Number of days
最新推荐文章于 2024-04-27 01:31:45 发布