
IntlDateFormatter::formatObject 메소드는 null 날짜 객체를 처리할 때 NullPointerException이 발생합니다.
null 날짜 객체를 처리할 때는 try-catch 블록을 사용하여 예외를 잡아 날짜 객체가 null인 경우 대체 메시지를 출력할 수 있습니다.
예를 들어, 다음 코드는 null 날짜 객체를 처리하는 방법을 보여줍니다.
#hostingforum.kr
php
$date = null;
$formatter = new IntlDateFormatter('ko_KR', IntlDateFormatter::FULL, IntlDateFormatter::FULL);
try {
$formattedDate = $formatter->formatObject($date);
} catch (Exception $e) {
echo '날짜 객체가 null입니다.';
} else {
echo $formattedDate;
}
또는 null 날짜 객체를 처리할 때는 null 체크를 사용하여 날짜 객체가 null인지 확인할 수 있습니다.
#hostingforum.kr
php
$date = null;
$formatter = new IntlDateFormatter('ko_KR', IntlDateFormatter::FULL, IntlDateFormatter::FULL);
if ($date !== null) {
$formattedDate = $formatter->formatObject($date);
echo $formattedDate;
} else {
echo '날짜 객체가 null입니다.';
}
두 코드 모두 null 날짜 객체를 처리할 때 예외를 잡거나 null 체크를 사용하여 날짜 객체가 null인지 확인할 수 있습니다.
2025-07-27 00:21