2
13693261870
2022-09-16 653761a31dfeb50dd3d007e892d69c90bf0cdafc
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
package com.landtool.lanbase.common.utils;
 
import java.security.InvalidParameterException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
 
/**
 * @author lanbase
 * @Description: TODO(日期处理)
 * @date 2017-6-23 15:07
 */
public class DateUtils {
    /** 时间格式(yyyy-MM-dd) */
    public final static String DATE_PATTERN = "yyyy-MM-dd";
    /** 时间格式(yyyy-MM-dd HH:mm:ss) */
    public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
    
    public static String format(Date date) {
        return format(date, DATE_PATTERN);
    }
 
    public static String format(Date date, String pattern) {
        if(date != null){
            SimpleDateFormat df = new SimpleDateFormat(pattern);
            return df.format(date);
        }
        return null;
    }
 
    /**
     * 统计两个日期之间包含的天数。
     *
     * @param date1
     * @param date2
     * @return
     */
    public static int getDayDiff(Date date1, Date date2) {
        if (date1 == null || date2 == null) {
            throw new InvalidParameterException("date1 and date2 cannot be null!");
        }
        long millSecondsInOneDay = 24 * 60 * 60 * 1000;
        return (int) ((date1.getTime() - date2.getTime()) / millSecondsInOneDay);
    }
 
    //根据选择时间补全系统时分秒
    public static Timestamp getFunllDate(Timestamp selectDate){
        if(selectDate != null){
            String dateStr = selectDate.toString().substring(0,10);
            //系统时间时分秒
            Calendar sysdate = Calendar.getInstance();
            dateStr += " "+ sysdate.get(Calendar.HOUR_OF_DAY) + ":"
                    + sysdate.get(Calendar.MINUTE) + ":"
                    + sysdate.get(Calendar.SECOND);
            return Timestamp.valueOf(dateStr);
        }else{
            return  selectDate;
        }
    }
}