java 시간합치기
업무를 하다보니 로그분석할일이 가끔있다
그래서 그냥 시간내서 혼자 만들어본것
txt파일에서
Fileinput 클래스에서 배열로읽어와서,
배열의 원소들을 가지고 장난
이전시간의 종료시간과 다음시작시간의 시작시간이 1시간 이내일때는 하나의 구간으로 합치기
예) 이전시간의 종료시간 : 11:11:12
다음시간의 시작시간 : 11:30:04
두 시간의 시간차이 : 대략 18:xx
한시간이 안넘는다
이럴때는 시간 구간을 합쳐버리기
fileinput은 패스.
샘플)
08:01:05 ~ 11:11:12
11:30:04 ~ 13:30:05
15:00:10 ~ 18:10:09
public class maintest {
public static void main(String[] args) {
FileInput fi = new FileInput();
String[] input = fi.run("D:\\test\\snd_sample.txt");
for (int i = 0; i < input.length; i++) {
System.out.println(input[i]);
}
cal_test(input[0],input[1]);
time_trans(input[0]);
}
public static String cal_test(String a, String b){
String a1 = a.substring(0,8);
String a2 = a.substring(11);
String b1 = b.substring(0,8);
String b2 = b.substring(11);
String new1 = "";
//육안으로 확인하기위한 코드
if((Integer.valueOf(time_trans(b1)) - Integer.valueOf(time_trans(a2))) < 3600){
new1 = a1 + " ~ " + b2;
}else if ((Integer.valueOf(time_trans(b1)) - Integer.valueOf(time_trans(a2))) > 3600){
new1 = a;
} // 추가로 다른 로직이 들어가야하나, 귀찮아서 넘김 //이코드는 잘 합쳐지나만을 보기 위한 것
System.out.println(new1);
return null;
}
public static int time_trans(String a){
//두 시간의 초를 계산해서 차이가 3600보다 작으면 1시간 이내, 3600보다 크면 1시간 초과
int si = Integer.valueOf(a.substring(0,2));
int bun = Integer.valueOf(a.substring(3,5));
int cho = Integer.valueOf(a.substring(6,8));
int result = (si*3600 + bun*60 + cho);
System.out.println(result);
return result;
}
}
햐.....
'Programing > JAVA' 카테고리의 다른 글
selenium Test (0) | 2018.10.25 |
---|---|
UDP 네트워크 프로그래밍 샘플 (0) | 2018.10.24 |
java 쓰레드 예제 (0) | 2018.03.19 |
jxl 을 이용한 엑셀쓰기에서, 입력받은 수(원하는 수)만큼 시트 생성하기 (0) | 2018.02.22 |
로또생성 코드 (0) | 2018.02.22 |