
IntlDateFormatter 클래스의 setCalendar 메서드는 GregorianCalendar 클래스의 인스턴스를 사용하여 날짜 형식을 설정할 수 있습니다.
한국의 날짜 형식은 년월일 형식으로 사용하려고 하시면, GregorianCalendar 클래스의 getInstance() 메서드를 사용하여 현재 날짜 형식을 얻은 후, setCalendar 메서드를 사용하여 설정할 수 있습니다.
예를 들어, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
java
import java.util.GregorianCalendar;
import java.util.Locale;
import java.text.IntlDateFormatter;
import java.text.ParsePosition;
public class Main {
public static void main(String[] args) {
// 한국의 날짜 형식을 설정
Locale locale = new Locale("ko", "KR");
GregorianCalendar calendar = new GregorianCalendar(locale);
// IntlDateFormatter 클래스의 인스턴스를 생성
IntlDateFormatter formatter = new IntlDateFormatter(locale);
// setCalendar 메서드를 사용하여 날짜 형식을 설정
formatter.setCalendar(calendar);
// 년월일 형식으로 날짜를 출력
String date = formatter.format(new Date());
System.out.println(date);
}
}
이 코드를 실행하면 년월일 형식으로 날짜를 출력할 수 있습니다.
2025-05-29 12:27