라이브러리

[PHP] IntlDateFormatter::getErrorCode - 마지막 작업의 오류 코드를 가져옵니다.




IntlDateFormatter::getErrorCode

`IntlDateFormatter::getErrorCode` 메소드는 IntlDateFormatter 객체의 마지막 오류 코드를 반환합니다. IntlDateFormatter 객체는 국제 날짜 포맷을 처리하는 클래스로, 날짜와 시간을 다양한 형식으로 변환하는 데 사용됩니다.

사용법


IntlDateFormatter::getErrorCode 메소드는 다음과 같이 사용할 수 있습니다.

#hostingforum.kr
php

 IntlDateFormatter::getErrorCode($formatter);



예제


IntlDateFormatter::getErrorCode 메소드는 IntlDateFormatter 객체의 마지막 오류 코드를 반환하므로, 오류가 발생한 경우에 사용할 수 있습니다.

#hostingforum.kr
php

<?php



// IntlDateFormatter 객체 생성

$formatter = new IntlDateFormatter('ko_KR', IntlDateFormatter::FULL, IntlDateFormatter::FULL);



// 날짜 포맷 오류 발생

try {

    $formatter->format('2022-01-01');

} catch (Exception $e) {

    // 오류 코드 얻기

    $errorCode = $formatter->getErrorCode();

    echo "오류 코드: $errorCode
";

}



?>



오류 코드


IntlDateFormatter::getErrorCode 메소드는 다음 오류 코드를 반환할 수 있습니다.

* `IntlDateFormatter::ERR_INVALID_FORMAT`
+ 유효하지 않은 포맷 문자열
* `IntlDateFormatter::ERR_INVALID_TYPE`
+ 유효하지 않은 형식
* `IntlDateFormatter::ERR_INVALID_VALUE`
+ 유효하지 않은 날짜 또는 시간 값
* `IntlDateFormatter::ERR_OUT_OF_RANGE`
+ 날짜 또는 시간 값이 유효하지 않은 범위에 속함
* `IntlDateFormatter::ERR_PARSE`
+ 날짜 또는 시간 값을 파싱할 수 없음

참고


IntlDateFormatter::getErrorCode 메소드는 오류가 발생한 경우에 사용할 수 있습니다. 오류가 발생하지 않은 경우, 0을 반환합니다. IntlDateFormatter 객체를 사용할 때, 오류를 처리하는 코드를 작성하는 것이 좋습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 442 페이지

검색

게시물 검색