113 lines
3.3 KiB
Java
113 lines
3.3 KiB
Java
package itn.com.cmm.util;
|
|
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.Month;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.Date;
|
|
|
|
/**
|
|
*
|
|
* @author : 이호영
|
|
* @fileName : DateUtil.java
|
|
* @date : 2023.04.06
|
|
* @description : Date 다루는 Util
|
|
* ===========================================================
|
|
* DATE AUTHOR NOTE
|
|
* ----------------------------------------------------------- *
|
|
* 2023.04.06 이호영 최초 생성
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
public final class DateUtil {
|
|
|
|
|
|
/**
|
|
* @methodName : getTodayYearAndMonthAndFirstDay
|
|
* @author : 이호영
|
|
* @date : 2023.04.06
|
|
* @description : 해당 년월일 구하기 : 일은 1일
|
|
* @return ex) 2023/04/01
|
|
*/
|
|
public static String getTodayYearAndMonthAndFirstDay() {
|
|
LocalDate currentDate = LocalDate.now();
|
|
return LocalDate.of(currentDate.getYear(), currentDate.getMonthValue(), 1)
|
|
.format( DateTimeFormatter.ofPattern("yyyy/MM/dd"));
|
|
}
|
|
|
|
/**
|
|
* @methodName : getTodayYearAndMonthAndLastDay
|
|
* @author : 이호영
|
|
* @date : 2023.04.06
|
|
* @description : 해당 년월일 구하기 : 일은 마지막일
|
|
* @return ex) 2023/04/30
|
|
*/
|
|
public static String getTodayYearAndMonthAndLastDay() {
|
|
LocalDate currentDate = LocalDate.now();
|
|
return LocalDate.of(currentDate.getYear(), currentDate.getMonthValue(), currentDate.lengthOfMonth())
|
|
.format( DateTimeFormatter.ofPattern("yyyy/MM/dd"));
|
|
}
|
|
|
|
|
|
/**
|
|
* @methodName : getNowYearToString
|
|
* @author : 이호영
|
|
* @date : 2023.04.07
|
|
* @description : 현재 연도
|
|
* @return : String
|
|
*/
|
|
public static String getNowYearToString() {
|
|
return Integer.toString(LocalDate.now().getYear());
|
|
}
|
|
|
|
/**
|
|
* @methodName : getNowMonthToString
|
|
* @author : 이호영
|
|
* @date : 2023.04.07
|
|
* @description : 현재 월
|
|
* @return : String
|
|
*/
|
|
public static String getNowMonthToString() {
|
|
LocalDate currentDate = LocalDate.now();
|
|
return Integer.toString(currentDate.getMonthValue());
|
|
}
|
|
|
|
/**
|
|
* @methodName : getNowDayToString
|
|
* @author : 이호영
|
|
* @date : 2023.04.07
|
|
* @description : 현재 일
|
|
* @return : String
|
|
*/
|
|
public static String getNowDayToString() {
|
|
LocalDate currentDate = LocalDate.now();
|
|
return Integer.toString(currentDate.getDayOfMonth());
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @methodName : getNowDayToString
|
|
* @author : 이호영
|
|
* @date : 2023.08.08
|
|
* @description : yyyy-MM-dd HH:mm:ss.S 형식을 yyyy-MM-dd HH:mm 로 변환
|
|
* @return
|
|
* @throws ParseException
|
|
*/
|
|
public static String getChangFormatS(String str) throws ParseException {
|
|
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); // 원본 형식
|
|
Date date = inputFormat.parse(str); // 문자열을 날짜 객체로 변환
|
|
|
|
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); // 원하는 출력 형식
|
|
String formattedDate = outputFormat.format(date); // 날짜 객체를 원하는 형식의 문자열로 변환
|
|
|
|
return formattedDate; // 출력: 2023-08-07 09:36
|
|
}
|
|
|
|
|
|
|
|
}
|