|
|
|
|
@ -229,21 +229,39 @@ public class DateUtil {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 날짜를 짧은 형식으로 변환 (YYYYMMDD -> YY.M.D)
|
|
|
|
|
* 날짜를 짧은 형식으로 변환 (YYYYMMDD 또는 YYYY-MM-DD -> YY.M.D)
|
|
|
|
|
* 예: 20250903 -> 25.9.3
|
|
|
|
|
* 예: 2025-09-03 -> 25.9.3
|
|
|
|
|
*
|
|
|
|
|
* @param dateStr 날짜 문자열 (yyyyMMdd 형식)
|
|
|
|
|
* @param dateStr 날짜 문자열 (yyyyMMdd 또는 yyyy-MM-dd 형식)
|
|
|
|
|
* @return YY.M.D 형식의 날짜 문자열, 변환 실패 시 원본 문자열 반환
|
|
|
|
|
*/
|
|
|
|
|
public static String formatToShortDate(String dateStr) {
|
|
|
|
|
if (dateStr == null || dateStr.length() != 8) {
|
|
|
|
|
if (dateStr == null) {
|
|
|
|
|
return dateStr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
String year = dateStr.substring(2, 4); // YY
|
|
|
|
|
int month = Integer.parseInt(dateStr.substring(4, 6)); // M (앞의 0 제거)
|
|
|
|
|
int day = Integer.parseInt(dateStr.substring(6, 8)); // D (앞의 0 제거)
|
|
|
|
|
String trimmed = dateStr.trim();
|
|
|
|
|
String year, monthStr, dayStr;
|
|
|
|
|
|
|
|
|
|
if (trimmed.length() == 8) {
|
|
|
|
|
// YYYYMMDD 형식
|
|
|
|
|
year = trimmed.substring(2, 4); // YY
|
|
|
|
|
monthStr = trimmed.substring(4, 6); // MM
|
|
|
|
|
dayStr = trimmed.substring(6, 8); // DD
|
|
|
|
|
} else if (trimmed.length() == 10) {
|
|
|
|
|
// YYYY-MM-DD 형식
|
|
|
|
|
year = trimmed.substring(2, 4); // YY
|
|
|
|
|
monthStr = trimmed.substring(5, 7); // MM
|
|
|
|
|
dayStr = trimmed.substring(8, 10); // DD
|
|
|
|
|
} else {
|
|
|
|
|
// 그 외 형식은 원본 반환
|
|
|
|
|
return dateStr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int month = Integer.parseInt(monthStr); // M (앞의 0 제거)
|
|
|
|
|
int day = Integer.parseInt(dayStr); // D (앞의 0 제거)
|
|
|
|
|
|
|
|
|
|
return year + "." + month + "." + day;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|