- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to check if two dates are equal
Let us first declare objects of LocalDate −
Date 1
LocalDate dateOne = LocalDate.now();
Date 2
LocalDate dateTwo = LocalDate.of(dateOne.getYear(), dateOne.getMonth(), dateOne.getDayOfMonth());
Let us now use the equals () method to check if both the dates are same or not −
if (dateOne.equals(dateTwo)) { System.out.printf("
Both the dates are same!", dateOne, dateTwo); }
Example
import java.time.LocalDate; public class Demo { public static void main(String[] argv) { LocalDate dateOne = LocalDate.now(); LocalDate dateTwo = LocalDate.of(dateOne.getYear(), dateOne.getMonth(), dateOne.getDayOfMonth()); System.out.printf("Date One = "+dateOne); System.out.printf("
Date Two = "+dateTwo); if (dateOne.equals(dateTwo)) { System.out.printf("
Both the dates are same!", dateOne, dateTwo); } } }
Output
Date One = 2019-04-12 Date Two = 2019-04-12 Both the dates are same!
- Related Articles
- How to check if two dates are equal in Java 8?
- Golang program to check if two slices are equal
- How to check if two strings are equal in Java?
- Golang Program to Check If Two Arrays are Equal or Not
- Swift Program to Check if Two Arrays Are Equal or Not
- Java Program to Check if two strings are anagram
- Java program to check if two given matrices are identical
- How to check if two nodes are equal in a JTree with Java?
- How to check if two matrices are equal in R?
- Check whether two HashSet are equal in Java
- Check if two SortedSet objects are equal in C#
- Check if two BitArray objects are equal in C#
- Check if two ArrayList objects are equal in C#
- Check if two HashSet objects are equal in C#
- Check if two HybridDictionary objects are equal in C#

Advertisements