728x90
반응형
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class DateFormatExample {
public static void main(String[] args) {
// 입력된 8자리 숫자 문자열
String inputDate = "20241118"; // 예: 2024년 11월 18일
// 원래 형식의 DateTimeFormatter 정의
DateTimeFormatter originalFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
// 원하는 출력 형식 정의 (년월일)
DateTimeFormatter targetFormatterKor = DateTimeFormatter.ofPattern("yyyy년 MM월 dd일");
// 문자열을 LocalDate로 변환
LocalDate date = LocalDate.parse(inputDate, originalFormatter);
// 변환된 형식으로 출력
String formattedDateKor = date.format(targetFormatterKor);
// 결과 출력
System.out.println("변환된 날짜 (년월일 형식): " + formattedDateKor);
}
}
728x90
반응형
'JAVA' 카테고리의 다른 글
[JAVA] Stream으로 List 중복 제거 (0) | 2024.11.17 |
---|---|
[JAVA] BigDecimal 빼기 (0) | 2024.11.16 |
[JAVA] BigDecimal 곱하기 (0) | 2024.11.12 |
[JAVA] BigDecimal 더하기 (0) | 2024.11.10 |
[JAVA] 요일구하기 (영어) (0) | 2024.11.09 |