1 | package movingdialog;
|
---|
2 |
|
---|
3 | import java.text.ParseException;
|
---|
4 | import java.time.LocalDate;
|
---|
5 | import java.time.ZoneId;
|
---|
6 | import java.time.format.DateTimeFormatter;
|
---|
7 |
|
---|
8 | import org.junit.Ignore;
|
---|
9 | import org.junit.Test;
|
---|
10 |
|
---|
11 | public class dateParseTest {
|
---|
12 | // LocalDate date1 = LocalDate.of(2021, 12, 17); // dec 17 2021
|
---|
13 | // LocalDate date2 = LocalDate.of(2021, 1, 7); // jan 7
|
---|
14 |
|
---|
15 | @Test
|
---|
16 | public void parseDateTest1() throws ParseException {
|
---|
17 | System.out.println(getSeconds("17 12 2021", "d M y"));
|
---|
18 | System.out.println(getSeconds("7 1 2021", "d M y"));
|
---|
19 | System.out.println(getSeconds("7 1 21", "d M y"));
|
---|
20 | }
|
---|
21 |
|
---|
22 | @Test
|
---|
23 | public void parseDateTest2() throws ParseException {
|
---|
24 | System.out.println(getSeconds("17-12-2021", "d-M-y"));
|
---|
25 | System.out.println(getSeconds("7-1-2021", "d-M-y"));
|
---|
26 | System.out.println(getSeconds("7-1-21", "d-M-y"));
|
---|
27 | }
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Maybe if we can figure out how this parser pareses NAMES of month...
|
---|
31 | */
|
---|
32 | @Ignore
|
---|
33 | @Test
|
---|
34 | public void parseDateTest3() throws ParseException {
|
---|
35 | System.out.println(getSeconds("17 dec 2021", "d LLL y"));
|
---|
36 | }
|
---|
37 |
|
---|
38 | private double getSeconds(String date, String format) {
|
---|
39 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
---|
40 |
|
---|
41 | return LocalDate.parse(date, formatter)
|
---|
42 | .atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli()
|
---|
43 | / 1000d;
|
---|
44 |
|
---|
45 | }
|
---|
46 | }
|
---|