yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.qianwen.smartman.modules.tpm.utils;
 
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import com.qianwen.smartman.common.constant.DateConstant;
 
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/tpm/utils/DateUtils.class */
public class DateUtils {
    public static Date stringToDate(String time) throws Exception {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DateConstant.PATTERN_DATE);
        Date date = simpleDateFormat.parse(time);
        return date;
    }
 
    public static String getStringDate(Date time) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DateConstant.PATTERN_DATE);
        String date = simpleDateFormat.format(time);
        return date;
    }
 
    public static boolean isToday(String time) throws Exception {
        SimpleDateFormat fmt = new SimpleDateFormat(DateConstant.PATTERN_DATE);
        Date date = fmt.parse(time);
        if (fmt.format(date).toString().equals(fmt.format(new Date()).toString())) {
            return true;
        }
        return false;
    }
 
    public static String dateToString(Date time) {
        SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
        return fmt.format(time);
    }
 
    public static long getDaySub(String beginDateStr, String endDateStr) {
        long day = 0;
        SimpleDateFormat format = new SimpleDateFormat(DateConstant.PATTERN_DATE);
        try {
            Date beginDate = format.parse(beginDateStr);
            Date endDate = format.parse(endDateStr);
            day = (endDate.getTime() - beginDate.getTime()) / 86400000;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return day;
    }
 
    public static Date plusDay(Date data, int num) {
        new Date();
        new SimpleDateFormat(DateConstant.PATTERN_DATE_TIME);
        Calendar ca = Calendar.getInstance();
        ca.setTime(data);
        ca.add(5, num);
        Date currdate = ca.getTime();
        return currdate;
    }
 
    public static LocalDateTime dateToLocalDateTime(Date date) {
        Instant instant = date.toInstant();
        ZoneId zone = ZoneId.systemDefault();
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
        return localDateTime;
    }
 
    public static Date localDateTimeToDate(LocalDateTime localDateTime) {
        Date date = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
        return date;
    }
}