How to use Java to determine whether a date is earlier or later than another date
Editor to share with you how to use Java to judge whether the date is earlier or later than another date, I believe most people do not know much about it, so share this article for your reference. I hope you will gain a lot after reading this article. Let's learn about it together.
Use Java to determine whether the date is earlier or later than another date
Another common operation at work is how to determine whether a given date is greater or less than a certain day. In Java 8, the LocalDate class has two types of methods, isBefore () and isAfter (), to compare dates. When the isBefore () method is called, it returns true if the given date is less than the current date.
Package com.shxt.demo02; import java.time.LocalDate; import java.time.temporal.ChronoUnit; public class Demo11 {public static void main (String [] args) {LocalDate today = LocalDate.now (); LocalDate tomorrow = LocalDate.of (2018 tomorrow.isAfter (today)) {System.out.println (date after ":" + tomorrow) } LocalDate yesterday = today.minus (1, ChronoUnit.DAYS); if (yesterday.isBefore (today)) {System.out.println ("previous date:" + yesterday);} above is all the content of the article "how to use Java to determine whether a date is earlier or later than another date". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!