Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Java to determine whether a date is earlier or later than another date

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report