于紫祥_1901
2020-08-12 3ea1e97b2a6d3304aed2e76097e2dc1bc4c42c61
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package com.moral.util;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
 
public class DatesUtil {
    public static List<String> getAllTheDateOftheMonth(Date date) {
        List<String> list = new ArrayList<String>();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.DATE, 1);
        int month = cal.get(Calendar.MONTH);
        while(cal.get(Calendar.MONTH) == month){
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
            String time=sf.format(cal.getTime());
            list.add(time);
            cal.add(Calendar.DATE, 1);
        }
        return list;
    }
    public static  String pinDate(String s) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime time = LocalDateTime.parse(s, df);
        LocalDateTime time1 = time.plusHours(8);
        int year = time1.getYear();
        int month = time1.getMonthValue();
        int day = time1.getDayOfMonth();
        int hour = time1.getHour();
        String m = "";
        String d = "";
        String h = "";
        if (month < 10) {
            m = "0" + month;
        }else {
            m=""+month;
        }
        if (day < 10) {
            d = "0" + day;
        }else {
            d=""+day;
        }
        if (hour < 10) {
            h = "0" + hour;
        }else {
            h=""+hour;
        }
        s = year + "-" + m + "-" + d + " " + h + ":00:00";
        return s;
    }
 
    public static void getList(List<Map<String, Object>> listMap,List list){
        if (listMap.size()<=8){
 
                list.add(listMap);
        }else{
        for (int i = 0; i < listMap.size(); i++) {
            List list1=new ArrayList();
            for (int j = i; j < i + 8; j++) {
                if (i==listMap.size()-7){
                    return;
                }else
                    list1.add(listMap.get(j));
            }
            list.add(list1);
        }}
    }
 
    public static List<String> findDaysStr(String beginTime,String endTime){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dBegin = null;
        Date dEnd = null;
        try {
            dBegin = sdf.parse(beginTime);
            dEnd = sdf.parse(endTime);
        }catch (ParseException e){
            e.printStackTrace();
        }
        List<String> daysStrList = new ArrayList<>();
        daysStrList.add(sdf.format(dBegin));
        Calendar calBegin = Calendar.getInstance();
        calBegin.setTime(dBegin);
        Calendar calEnd = Calendar.getInstance();
        calEnd.setTime(dEnd);
        while (dEnd.after(calBegin.getTime())) {
            calBegin.add(Calendar.DAY_OF_MONTH,1);
            String dayStar = sdf.format(calBegin.getTime());
            daysStrList.add(dayStar);
        }
 
        return daysStrList;
    }
 
    public static List<String> findHoursStr(String beginTime,String endTime){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date dBegin = null;
        Date dEnd = null;
        try {
            dBegin = sdf.parse(beginTime);
            dEnd = sdf.parse(endTime);
        }catch (ParseException e){
            e.printStackTrace();
        }
        List<String> daysStrList = new ArrayList<>();
        daysStrList.add(sdf.format(dBegin));
        Calendar calBegin = Calendar.getInstance();
        calBegin.setTime(dBegin);
        Calendar calEnd = Calendar.getInstance();
        calEnd.setTime(dEnd);
        while (dEnd.after(calBegin.getTime())) {
            calBegin.add(Calendar.HOUR,1);
            String dayStar = sdf.format(calBegin.getTime());
            daysStrList.add(dayStar);
        }
 
        return daysStrList;
    }
 
}