Home > Java > javaTutorial > body text

How to determine whether dates are equal in java

王林
Release: 2020-05-18 15:37:40
Original
6027 people have browsed it

How to determine whether dates are equal in java

You can use the equals() method in the Date class to compare.

Syntax:

boolean equals(Object date)
Copy after login

Returns true when the Date object calling this method is equal to the specified date, otherwise returns false.

(Recommended video tutorial: java video)

Specific code:

//1.利用Date的equals比较大小
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
String timeStr1 = "2020-02-12 12:45:45";
String timeStr2 = "2020-02-12 12:45:40";
Date date1 = sdf.parse(timeStr1);
Date date2 = sdf.parse(timeStr2);
if(date1.equals(date2)) {
	//相等
}
Copy after login

Recommended tutorial: Getting started with java development

The above is the detailed content of How to determine whether dates are equal in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!