1. 등록한 시간과 현재 시간을 비교 하여 10분이 넘어 갔을 경우 true & false 값 추출 메서드
2. 확장자 제거 메서드
/**
* 현재 시간과 DB에 있는 등록일 시간을 가져와서 10분이 넘어갔을때 true & false 결과 값 생성
*
* @param currentTime
* @param givenTime
* @param secondsThreshold
* @return
*/
public static boolean checkTimeDifference(Date currentTime, Date givenTime, int minutesThreshold) {
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
// 현재 시간을 시분초 문자열로 변환
String currentTimeString = dateFormat.format(currentTime);
// 주어진 시간을 시분초 문자열로 변환
String givenTimeString = dateFormat.format(givenTime);
// 시간 문자열을 Date 객체로 파싱
Date parsedCurrentTime = null;
Date parsedGivenTime = null;
try {
parsedCurrentTime = dateFormat.parse(currentTimeString);
parsedGivenTime = dateFormat.parse(givenTimeString);
} catch (ParseException e) {
e.printStackTrace();
}
// 현재 시간과 주어진 시간 간의 차이 계산 (분 단위)
long millisecondsDifference = parsedCurrentTime.getTime() - parsedGivenTime.getTime();
long minutesDifference = millisecondsDifference / (60 * 1000);
// 주어진 시간과의 차이가 지정된 임계값보다 큰지 확인
return minutesDifference >= minutesThreshold;
}
/**
* 파일 확장자명 .이후 제거 하기
*
* @param fileName
* @return
*/
public static String removeExtension(String fileName) {
// 파일명에서 마지막 점(.)의 인덱스를 찾습니다.
int lastDotIndex = fileName.lastIndexOf('.');
// 파일명에서 확장자를 제외한 부분을 추출합니다.
String fileNameWithoutExtension = (lastDotIndex != -1) ? fileName.substring(0, lastDotIndex) : fileName;
return fileNameWithoutExtension;
}
'Web > 현업 경험' 카테고리의 다른 글
커스텀 URL 이동 후 URL에 붙는 파라메터 제거 후 리다이렉트 처리 하는 방법 (0) | 2024.04.16 |
---|---|
CKEDITOR 4와 BOOTSTRAP MODAL 함께시 INPUT DISABLED BUG 해결 방법 (0) | 2022.07.08 |
자바 파일 이름 변경 하기 (0) | 2020.09.11 |
JSCH 라이브러리를 사용해서 SFTP / SSH 클라이언트 구현하기 (0) | 2020.08.21 |
[Lucy XSS filter] 3번 클릭 만에 적용하기! - XSS방지, 방어, 네이버XSS (0) | 2019.04.05 |