44323
2023-11-27 aa925d851857f50eff0556411366690d9a78a0e5
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
package com.dsh.other.util;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
 
 
//根据当前传入的时间,返回距离当前时间多少天
 
public class StudyTimeUtil {
    private StudyTimeUtil() {
    }
 
    /**
     * 获取两个时间的间隔(秒)Obtain the time difference between two instances (in seconds).
     *
     * @param startDate 开始的时间
     * @return 返回当前时间与开始时间的相差天数
     */
    public static int getDateBetween(Date startDate) throws ParseException {
        Date endDate = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        long startDateTime = dateFormat.parse(dateFormat.format(startDate)).getTime();
        long endDateTime = dateFormat.parse(dateFormat.format(endDate)).getTime();
        int days = (int) ((endDateTime - startDateTime) / (1000 * 3600 * 24));
        return days;
    }
 
    public static Date getStartDate(LocalDateTime localDate) {
        Date date = Date.from(localDate.atZone(ZoneId.systemDefault()).toInstant());
        return date;
    }
 
 
}