TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Java Date Comparison
Alagunila Meganathan
Sep 30, 2019
7.4
k
0
2
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
In this blog, I am going to explain about the date comparison program in Java.
DateComparison.rar
Introduction
In this blog, I am going to explain the program for the date comparison program in Java
Software Requirements
Java, Notepad.
Program
import
java.util.Date;
import
java.text.ParseException;
import
java.text.SimpleDateFormat;
public
class
DateComparison {
private
static
void
DateComparison() {
Date comparetodaydate =
new
Date();
Date comparedate = (Date) comparetodaydate.clone();
Date comparedate1970 =
new
Date(
24
L *
60
L *
60
L *
1000
L);
System.out.println(
"Comparison of two dates by using the equals() method:"
);
System.out.println();
System.out.println(
"Today's date:"
+ comparetodaydate);
System.out.println(
"Compairing date:"
+ comparedate);
if
(comparetodaydate.equals(comparedate)) {
System.out.println(
"The two dates are equal"
);
}
else
{
System.out.println(
"The two dates are not equal"
);
}
System.out.println();
System.out.println(
"Comparison of two dates by using the equals() method:"
);
System.out.println();
System.out.println(
"Today's date:"
+ comparetodaydate);
System.out.println(
"Compairing date:"
+ comparedate1970);
if
(comparetodaydate.equals(comparedate1970)) {
System.out.println(
"The two dates are equal"
);
}
else
{
System.out.println(
"The two dates are not equal"
);
}
System.out.println();
System.out.println(
"Comparison of two dates by using the before() method:"
);
System.out.println();
System.out.println(
"Today's date:"
+ comparetodaydate);
System.out.println(
"Compairing date:"
+ comparedate1970);
if
(comparetodaydate.before(comparedate1970)) {
System.out.println(
"Today's date comes before the compairing date"
);
}
else
{
System.out.println(
"Today's date does not come before the compairing date"
);
}
System.out.println();
System.out.println(
"Comparison of two dates by using the after() method::"
);
System.out.println();
System.out.println(
"Today's date:"
+ comparetodaydate);
System.out.println(
"Compairing date:"
+ comparedate1970);
if
(comparetodaydate.after(comparedate1970)) {
System.out.println(
"Today's date comes after the compairing date"
);
}
else
{
System.out.println(
"Today's date does not come after the compairing date"
);
System.out.println();
}
System.out.println();
}
public
static
void
main(String[] args) {
System.out.println();
DateComparison();
}
}
Output
Java
Date Comparison
Next Recommended Reading
Step By Step Process To See The Date And Time Using Java