-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompareDate.java
More file actions
41 lines (33 loc) · 1023 Bytes
/
CompareDate.java
File metadata and controls
41 lines (33 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package date;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/*
*
Letter Description Examples
y Year 2013
M Month in year July, 07, 7
d Day in month 1-31
E Day name in week Friday, Sunday
a Am/pm marker AM, PM
H Hour in day 0-23
h Hour in am/pm 1-12
m Minute in hour 0-60
s Second in minute 0-60
*
* */
public class CompareDate {
public static void main(String[] args) {
DateTimeFormatter sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate date1 = LocalDate.of(2009, 12, 31);
LocalDate date2 = LocalDate.of(2010, 01, 31);
System.out.println("date1 : " + sdf.format(date1));
System.out.println("date2 : " + sdf.format(date2));
if(date1.isAfter(date2))
System.out.println("date1 after date2");
if(date1.isBefore(date2))
System.out.println("date1 is before date2");
if(date1.isEqual(date2))
System.out.println("date1 equel date2");
System.out.println(date1.compareTo(date2)); //-1 before, 1 after, 0 equel
}
}