File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
package itn.com.cmm.util;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;
public final class MJUtil {
/**
* 휴대폰번호 유효성 체크
* true, false 반환
* 대시 유무 상관없음
*/
public static boolean checkHpNum(String str) {
String regExp = "^(050[2345678]{1}|01[016789]{1})-?[0-9]{3,4}-?[0-9]{4}$";
//String regExp = "^(01[016789]{1}|070)-?[0-9]{3,4}-?[0-9]{4}$";
return Pattern.matches(regExp, str);
}
/**
* 휴대폰번호 대시('-') 추가
* 대시 유무 상관없음
* 유효성 맞지 않을시 변환안됨.
*/
public static String addDash(String str) {
String regExp = "(^01[016789]{1}|070)([0-9]{3}|[0-9]{4})([0-9]{4})$";
String chgf = "$1-$2-$3";
return str.replaceFirst(regExp, chgf);
}
/**
* 팩스 번호 유효성 체크
* true, false 반환
* 앞 3자리를 체크 함
* -- 전국 지역번호
* 02 서울특별시
031 경기도
032 인천광역시
033 강원도
041 충청남도
042 대전광역시
043 충청북도
044 세종특별자치시
051 부산광역시
052 울산광역시
053 대구광역시
054 경상북도
055 경상남도
061 전라남도
062 광주광역시
063 전라북도
064 제주특별자치도
-- 타사부가번호
030*
050*
060
070
080
1**
위 번호로 시작하는 팩스 번호만 허용함.
*/
public static boolean checkFaxNum(String str) {
boolean result = false;
if(str.equals("") || str == null) {
return result = false;
}else {
str = str.replaceAll("-", "");
String subNum = str.substring(0,3);
String regExp = "^(02[0-9]{1}|030|050|060|070|080|0[3-6]{1}[1-5]{1}|1[0-9]{1}[0-9]{1})$";
result = Pattern.matches(regExp, subNum);
}
return result;
}
/**
* 현재 시간에서 몇분 뒤 시간 받아오기
*
*/
public static String getAfterTimerDate(int interval) {
Date now = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(now);
cal.add(Calendar.MINUTE, interval); //원하는 분을 더해서 시간을 구함
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String strDate = sdf.format(cal.getTime());
return strDate;
}
/**
* 현재 시간에서 몇달 뒤 시간 받아오기
*
* */
public static String getAfterTimerMonth(int interval) {
Date now = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(now);
cal.add(Calendar.MONTH, interval); //원하는 분을 더해서 시간을 구함
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String strDate = sdf.format(cal.getTime());
return strDate;
}
/**
* 현재 시간 받아오기
*
* */
public static String getRealTime() {
Date now = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(now);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String strDate = sdf.format(cal.getTime());
return strDate;
}
/**
* 오늘 날짜와 파라미터로 받은 날짜 사이의 차이를 비교
* date1과 date2 를 비교했을 때
* 같은 날짜면 0 반환
* 이전면 음수 반환
* 이후면 양수 반환
*
* */
public static boolean getCompareDate(String date) throws Exception {
boolean rtnType = false;
date = date.replaceAll("-", "/");//날짜에 하이픈(-)을 슬러쉬(/)로 변환
SimpleDateFormat sdformat = new SimpleDateFormat("yyyy/MM/dd");
Date nowDate = sdformat.parse(getRealTime());
Date endDate = sdformat.parse(date);
if(nowDate.compareTo(endDate) > 0) {
System.out.println("date1은 date2 이후입니다.");
rtnType = false;
} else if(nowDate.compareTo(endDate) < 0) {
System.out.println("date1은 date2 이전입니다.");
rtnType = true;
} else if(nowDate.compareTo(endDate) == 0) {
System.out.println("같은 날짜입니다.");
rtnType = true;
}
return rtnType;
}
/**
* 오늘 날짜와 파라미터로 받은 날짜 사이의 차이를 비교
* date1과 date2 를 비교했을 때
* 같은 날짜면 0 반환
* 이전면 음수 반환
* 이후면 양수 반환
*
* */
public static String getCompareDateToSeconds(String date) throws Exception {
String rtnType = "";
date = date.replaceAll("-", "/");//날짜에 하이픈(-)을 슬러쉬(/)로 변환
SimpleDateFormat sdformat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
System.out.println(getRealTime());
Date nowDate = sdformat.parse(getRealTime());
Date endDate = sdformat.parse(date);
if(nowDate.compareTo(endDate) > 0) {
System.out.println("date1은 date2 이후입니다.");
rtnType = "after";
} else if(nowDate.compareTo(endDate) < 0) {
System.out.println("date1은 date2 이전입니다.");
rtnType = "before";
} else if(nowDate.compareTo(endDate) == 0) {
System.out.println("같은 날짜입니다.");
rtnType = "equal";
}
return rtnType;
}
/**
* 현재 날짜와 파라미터 날짜 사이의 차이 구하기
* 초 단위로 계산하기
* */
public static long getDiffDateSec(String date) throws Exception{
date = date.replaceAll("-", "/");//날짜에 하이픈(-)을 슬러쉬(/)로 변환
Date format1 = new SimpleDateFormat("yyyy/MM/dd").parse(getRealTime());
Date format2 = new SimpleDateFormat("yyyy/MM/dd").parse(date);
long diffSec = (format1.getTime() - format2.getTime()) / 1000; //초 차이
return diffSec;
}
/**
* 현재 날짜와 파라미터 날짜 사이의 차이 구하기
* 분 단위로 계산하기
* */
public static long getDiffDateMin(String date) throws Exception{
date = date.replaceAll("-", "/");//날짜에 하이픈(-)을 슬러쉬(/)로 변환
Date format1 = new SimpleDateFormat("yyyy/MM/dd").parse(getRealTime());
Date format2 = new SimpleDateFormat("yyyy/MM/dd").parse(date);
long diffMin = (format1.getTime() - format2.getTime()) / 60000; //분 차이
return diffMin;
}
/**
* 현재 날짜와 파라미터 날짜 사이의 차이 구하기
* 시 단위로 계산하기
* */
public static long getDiffDateHour(String date) throws Exception{
date = date.replaceAll("-", "/");//날짜에 하이픈(-)을 슬러쉬(/)로 변환
Date format1 = new SimpleDateFormat("yyyy/MM/dd").parse(getRealTime());
Date format2 = new SimpleDateFormat("yyyy/MM/dd").parse(date);
long diffHour = (format1.getTime() - format2.getTime()) / 3600000; //시 차이
return diffHour;
}
/**
* 현재 날짜와 파라미터 날짜 사이의 차이 구하기
* 일 단위로 계산하기
* */
public static long getDiffDateDay(String date) throws Exception{
date = date.replaceAll("-", "/");//날짜에 하이픈(-)을 슬러쉬(/)로 변환
Date format1 = new SimpleDateFormat("yyyy/MM/dd").parse(getRealTime());
Date format2 = new SimpleDateFormat("yyyy/MM/dd").parse(date);
long diffSec = (format1.getTime() - format2.getTime()) / 1000; //초 차이
long diffDays = diffSec / (24*60*60); //일자수 차이
return diffDays;
}
// 오늘 날짜
public static String getTodayDate() throws Exception {
Date toDay = new Date();
SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
String rtnDay = date.format(toDay);
return rtnDay;
}
// 한달 전 날짜
public static String getBefore1MonthDate() throws Exception {
Calendar mon = Calendar.getInstance();
mon.add(Calendar.MONTH , -1);
String beforeMonthDay = new java.text.SimpleDateFormat("yyyy-MM-dd").format(mon.getTime());
return beforeMonthDay;
}
public static String getBefore1DayDate() throws Exception {
Calendar mon = Calendar.getInstance();
mon.add(Calendar.DAY_OF_MONTH , -1);
String beforeMonthDay = new java.text.SimpleDateFormat("yyyy-MM-dd").format(mon.getTime());
return beforeMonthDay;
}
public static void main(String args[]) throws Exception {
System.out.println(new Date(System.currentTimeMillis()));
System.out.println(checkHpNum("070-85326650"));
System.out.println(addDash("07085326650"));
}
//리스트에서 중복 값 제거 후 리스트 반환
public static List<String> getDuplicateList(List<String> userBlockList){
List<String> dupliBlockList = new ArrayList<String>();
for(String phone : userBlockList) {
boolean chk = true;
for(String dupPhone : dupliBlockList) {
if(phone.equals(dupPhone)) {
chk = false;
}
}
if(chk) {
dupliBlockList.add(phone);
}
}
return dupliBlockList;
}
/**
* 사업자등록번호 대시('-') 추가
* 대시 유무 상관없음
* 유효성 맞지 않을시 변환안됨.
*/
public static String bizNoAddDash(String str) {
if(str == null) {
return str;
}
String regExp = "(\\d{3})(\\d{2})(\\d{5})$";
String chgf = "$1-$2-$3";
return str.replaceFirst(regExp, chgf);
}
}