DateUtilsTest.java
1.98 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
46
47
48
49
50
51
52
53
54
55
56
package com.credit.cy.user;
import com.credit.cy.common.utils.DateUtils;
import org.junit.jupiter.api.Test;
import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;
import java.util.Date;
/**
* @author wangshuaixin
* @Title: com.credit.cy.user.DateUtilsTest
* @Description: TODO
* @date 2024/04/12
*/
public class DateUtilsTest {
@Test
public void testDate() throws Exception {
Date startDate = DateUtils.getDayDate();
Date endDate = DateUtils.addDays(startDate, 1);
boolean sameDate = DateUtils.isSameDay(startDate, endDate);
System.out.println(sameDate);
LocalDate sDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate eDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
Period period = Period.between(sDate, eDate);
System.out.println("相差" + period.getYears() + "年" + period.getMonths() + "月" + period.getDays() + "天");
endDate = DateUtils.parseDate("2024-04-12", DateUtils.YYYY_MM_DD);
sameDate = DateUtils.isSameDay(startDate, endDate);
System.out.println(sameDate);
sDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
eDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
period = Period.between(sDate, eDate);
System.out.println("相差" + period.getYears() + "年" + period.getMonths() + "月" + period.getDays() + "天");
endDate = DateUtils.parseDate("2024-04-11", DateUtils.YYYY_MM_DD);
sameDate = DateUtils.isSameDay(startDate, endDate);
System.out.println(sameDate);
sDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
eDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
period = Period.between(sDate, eDate);
System.out.println("相差" + period.getYears() + "年" + period.getMonths() + "月" + period.getDays() + "天");
}
}