Calculating elapsed minutes between LocalDateTime instances
source link: https://www.kevinhooke.com/2024/01/11/calculating-elapsed-minutes-between-localdatetime-instances/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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).
CategoriesKev's BlogTagsdatetime, java, java.time, LocalDateTime
Leave a Reply Cancel reply
Your email address will not be published. Required fields are marked *
Comment *
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
Notify me of follow-up comments by email.
Notify me of new posts by email.
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Post navigation
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK