-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateCompare.java
More file actions
23 lines (18 loc) · 800 Bytes
/
DateCompare.java
File metadata and controls
23 lines (18 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// You are using Java
import java.util.Scanner;
import java.time.format.DateTimeFormatter;
import java.time.LocalDate;
class main {
public static void main (String[] args){
Scanner sc = new Scanner(System.in);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
String date1 = sc.nextLine();
String date2 = sc.nextLine();
LocalDate firstDate = LocalDate.parse(date1, formatter);
LocalDate secondDate = LocalDate.parse(date2, formatter);
if(firstDate.isEqual(secondDate))
System.out.println(date1 + " is equal to " + date2);
else
System.out.println(date1 + " is " + (firstDate.isBefore(secondDate)?"less than":"greater than") + " " + date2);
}
}