时间段内取出中间的日期和取日期的开始时间和结束时间

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
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class Time {

public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
public static SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

public static void main(String[] args) throws Exception {
List<Date> list = addDates("2019-02-01", "2019-02-05");
}

/**
* @param cntDateBeg 开始时间
* @param cntDateEnd 结束时间
* @return
*/
public static List<Date> addDates(String cntDateBeg, String cntDateEnd) {
List<Date> list = new ArrayList<>();
//拆分成数组
String[] dateBegs = cntDateBeg.split("-");
String[] dateEnds = cntDateEnd.split("-");
//开始时间转换成时间戳
Calendar start = Calendar.getInstance();
start.set(Integer.valueOf(dateBegs[0]), Integer.valueOf(dateBegs[1]) - 1, Integer.valueOf(dateBegs[2]));
Long startTIme = start.getTimeInMillis();
//结束时间转换成时间戳
Calendar end = Calendar.getInstance();
end.set(Integer.valueOf(dateEnds[0]), Integer.valueOf(dateEnds[1]) - 1, Integer.valueOf(dateEnds[2]));
Long endTime = end.getTimeInMillis();
//定义一个一天的时间戳时长
Long oneDay = 1000 * 60 * 60 * 24l;
Long time = startTIme;
//循环得出
while (time <= endTime) {
list.add(new Date(time));
time += oneDay;
}
return list;
}

/**
* 得到指定日期的一天的的最后时刻23:59:59
*
* @param date
* @return
*/
public static Date getFinallyDate(Date date) {
String temp = format.format(date);
temp += " 23:59:59";

try {
return format1.parse(temp);
} catch (Exception e) {
return null;
}
}

/**
* 得到指定日期的一天的开始时刻00:00:00
*
* @param date
* @return
*/
public static Date getStartDate(Date date) {
String temp = format.format(date);
temp += " 00:00:00";

try {
return format1.parse(temp);
} catch (Exception e) {
return null;
}
}
}

数组分页截取

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
import org.apache.poi.ss.formula.functions.T;

import java.util.*;


public class PageList {

/**
* 循环截取某页列表进行分页
* @param data
* @param nowPage
* @param pageSize
* @return
*/
public static List<Map<String, Object>> getPagedList(List<Map<String, Object>> data,int nowPage,int pageSize) {
int fromIndex = (nowPage - 1) * pageSize;
if (fromIndex >= data.size()) {
return Collections.emptyList();//空数组
}
if(fromIndex<0){
return Collections.emptyList();//空数组
}
int toIndex = nowPage * pageSize;
if (toIndex >= data.size()) {
toIndex = data.size();
}
return data.subList(fromIndex, toIndex);
}

}

Element Table表格取整数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
getColumns (param) {//表格求和
const { columns, data } = param;
const sums = [];
columns.forEach((column, index) => {
if (index == 0) {//第一行为合计
sums[index] = '合计';
return;
}
const prop = column.property//取出table每行对应的property
let allsum = 0;//定义一个总数
data.forEach((item, i) => {//遍历data的数据(table每行的数据)
let keys = Object.keys(item);//item对象数组取出属性名的数组
let kl = keys.length;//属性名数组的长度
for (let j = 0; j < kl; j++) {//遍历keys数组
let num = Number(Object.values(item)[j]);//取出属性名数组对应的值
if (keys[j] == prop) {//判断属性名和table每行的property是否相同
allsum += num;//相同则总数增加
}
}//再次返回遍历每行item
})
sums[index] = Math.floor(allsum * 100) / 100;//相同属性名的值相加后传入对应数组(保留两位小数)
})
return sums;
}