Skip to content

Instantly share code, notes, and snippets.

@ILapitan
Last active June 4, 2017 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ILapitan/20b5b788eea2b05c99ac697ebdd9989a to your computer and use it in GitHub Desktop.
Save ILapitan/20b5b788eea2b05c99ac697ebdd9989a to your computer and use it in GitHub Desktop.
Calculate the number of days between two dates in Java 1.8 (with time)
// input dates
final String start = "2010-01-15T00:00:00";
final String end = "2011-03-18T18:00:00";
// parse the dates
final LocalDateTime startDate = LocalDateTime.parse(start);
final LocalDateTime endDate = LocalDateTime.parse(end);
// calculate the number of days between start and end dates
long daysDuration = Duration.between(startDate, endDate).toDays();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment