yuzixiang
2020-05-19 e25c689888a0dd80d07ffc4e4a45bd290b3d010c
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.moral.util;
 
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
 
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;
    }
 
}