TimeUtils.java
1.32 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.bsth.util;
public class TimeUtils {
/**
* 时间差
* @param date1
* @param date2
* @return
*/
public static String getTimeDifference(String date1,String date2){
String[] temp1 = date1.split(":");
String[] temp2 = date2.split(":");
int m1 = Integer.parseInt(temp1[0])*60;
int s1 = Integer.parseInt(temp1[1]);
int m2 = Integer.parseInt(temp2[0])*60;
int s2 = Integer.parseInt(temp2[1]);
if(date1.compareTo(date2) > 0){
return ((m1+s1)-(m2+s2))+"";
} else {
return ((m2+s2)-(m1+s1))+"";
}
}
/**
* 是否是早高峰
* @param time
* @return
*/
public static boolean morningPeak(String time){
String[] temp = time.split(":");
int d1 = Integer.parseInt(temp[0])*60;
int d2 = Integer.parseInt(temp[1]);
//早高峰时间
int sj_0 = 6*60+31,sj_1 = 8*60+30;
if((d1+d2) >= sj_0 && (d1+d2) <= sj_1){
return true;
}else{
return false;
}
}
/**
* 是否是晚高峰
* @param time
* @return
*/
public static boolean evenignPeak(String time){
String[] temp = time.split(":");
int d1 = Integer.parseInt(temp[0])*60;
int d2 = Integer.parseInt(temp[1]);
//早高峰时间
int sj_0 = 16*60+1,sj_1 = 18*60;
if((d1+d2) >= sj_0 && (d1+d2) <= sj_1){
return true;
}else{
return false;
}
}
}