forked from nibnait/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateFormatTest.java
More file actions
45 lines (36 loc) · 1.21 KB
/
DateFormatTest.java
File metadata and controls
45 lines (36 loc) · 1.21 KB
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
42
43
44
45
package zzzTest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
/**
* Created by nibnait on 2016/11/5.
*/
public class DateFormatTest {
private static final String LocalDateTimeFormat = "yyyy-MM-dd HH:mm:ss";
private static final String LocalDateFormat = "yyyy-MM-dd";
public static void main(String[] args) {
System.out.println(toLocalDate(253392422400000l));
}
private static LocalDate toLocalDate(long time) {
SimpleDateFormat sdf = new SimpleDateFormat(LocalDateFormat);
String d = sdf.format(time);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(LocalDateFormat);
return LocalDate.parse(d, dtf);
}
private void teat01() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String str1 = "2016-11-01";
String str2 = "2016-11-02";
Date d1 = null;
Date d2 = null;
try {
d1 = format.parse(str1);
d2 = format.parse(str2);
} catch (ParseException e) {
e.printStackTrace();
}
System.out.println(d1.compareTo(d2));
}
}