DataTimeBetweenUtil.java
1.01 KB
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
package com.brframework.commoncms.utils;
import com.brframework.commonweb.exception.HandleException;
/**
* 时间区间格式
*
* @author 揭光智
* @date 2019/03/08
*/
public class DataTimeBetweenUtil {
/**
* 获取开始时间
*
* @param time 时间区间
* @return 开始时间
*/
public static String getStartTime(String time) {
return dealWithTime(time)[0];
}
/**
* 获取结束时间
*
* @param time 时间区间
* @return 结束时间
*/
public static String getEndTime(String time) {
return dealWithTime(time)[1];
}
private static String[] dealWithTime(String time) {
if (time == null) {
throw new HandleException("时间区间不能为null");
}
String[] times = time.split(",");
if (times.length != 2) {
throw new HandleException("时间区间格式不正确,正确的格式eg:2019-01-01 00:00:00,2019-02-01 00:00:00");
}
return times;
}
}