FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java8Examples/Java8Examples/src/date/CompareDate.java at master · suatoz/java8Examples · GitHub
suatoz
/
java8Examples
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java8Examples
/
Java8Examples
/
src
/
date
/
CompareDate.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
41 lines (33 loc) · 1023 Bytes
Breadcrumbs
java8Examples
/
Java8Examples
/
src
/
date
/
CompareDate.java
Copy path
File metadata and controls
41 lines (33 loc) · 1023 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
}
}
Back
|
FazBrowse Home
|
New Git URL