Skip to content

Instantly share code, notes, and snippets.

@ezhov-da
Last active December 12, 2020 17:56
Show Gist options
  • Save ezhov-da/ded1085c7a0c677f75fa854f9ac0f079 to your computer and use it in GitHub Desktop.
Save ezhov-da/ded1085c7a0c677f75fa854f9ac0f079 to your computer and use it in GitHub Desktop.
разница между датами
public class T {
public static void main(String[] args) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
LocalDate startDate = LocalDate.parse("28.01.2009", formatter);
LocalDate endDate = LocalDate.parse("05.03.2013", formatter);
Period period = Period.between(startDate, endDate);
System.out.println(period.getYears()); // 4
System.out.println(period.getMonths()); // 1
System.out.println(period.getDays()); // 5
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment