Get the App
SLTechnology News&Howtos  ›  Development  › 

How java uses the Date.before (), Date.after (), and Date.equals () methods

Shulou Source: shulou.com Published: 2022-06-01 03:05:23 10月05日 Update

Editor to share with you how java uses Date.before (), Date.after () and Date.equals () methods. I hope you will get something after reading this article. Let's discuss it together.

Date.before (), Date.after () and Date.equals ()

A semantically friendly way to compare two java.util.Date

@ Test

Void testDateCompare2 () throws ParseException {

SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd")

Date date1 = sdf.parse ("2009-12-31")

Date date2 = sdf.parse ("2019-01-31")

System.out.println ("date1:" + sdf.format (date1))

System.out.println ("date2:" + sdf.format (date2))

If (date1.after (date2)) {

System.out.println ("Date1 time is after Date2")

}

If (date1.before (date2)) {

System.out.println ("Date1 time is before Date2")

}

If (date1.equals (date2)) {

System.out.println ("Date1 time equals Date2")

}

}

Output result

Date1: 2009-12-31

Date2: 2019-01-31

Date1 time has finished reading this article before Date2. I believe you have some understanding of "how java uses Date.before (), Date.after () and Date.equals () methods". If you want to know more about it, please follow the industry information channel. Thank you for reading!

Tags: Time method article two done more knowledge results industry semantics information information channels channels output Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MySQL MariaDB Docker OPPO Reno