Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Java Date Comparison
WhatsApp
Alagunila Meganathan
5y
7.5
k
0
2
25
Blog
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
Up Next
Consuming WCF Service In Java
Ebook Download
View all
Coding Principles
Read by 2.7k people
Download Now!
Learn
View all
Membership not found