Calculating elapsed minutes between LocalDateTime instances

There’s many ways to this, like getting epoch millis, calculating the difference and then converting back into the units you need. With java.time apis and java.time.temporal.ChronoUnit you can calculate the difference between 2 LocalDateTime instances easily in one step with:

long elapsedMins = ChronoUnit.MINUTES.between(start, end);

I was looking for a refresher on how to do this and found my own post from 3 years ago in a Google search here (funny when that happens).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.