라이브러리

[PHP] IntlTimeZone::__construct - 직접 인스턴스화를 허용하지 않는 개인 생성자


IntlTimeZone::__construct는 PHP의 IntlTimeZone 클래스에서 사용할 수 있는 생성자입니다. IntlTimeZone 클래스는 시간대 정보를 처리하는 클래스로, IntlTimeZone::__construct는 시간대 정보를 초기화하는 데 사용됩니다.

IntlTimeZone::__construct의 사용법


IntlTimeZone::__construct는 두 가지 형태로 사용할 수 있습니다.

# 1. 시간대 ID를 사용하는 경우


IntlTimeZone::__construct는 시간대 ID를 사용하여 시간대 정보를 초기화할 수 있습니다. 시간대 ID는 IANA 시간대 이름으로, 예를 들어 "Asia/Seoul"이나 "America/New_York"와 같은 형태입니다.

#hostingforum.kr
php

use IntlTimeZone;



$timezone = IntlTimeZone::createTimeZone('Asia/Seoul');

echo $timezone->getID() . "
"; // Asia/Seoul



# 2. UTC 오프셋을 사용하는 경우


IntlTimeZone::__construct는 UTC 오프셋을 사용하여 시간대 정보를 초기화할 수 있습니다. UTC 오프셋은 시간대에서 UTC와의 차이로, 예를 들어 +9 또는 -5와 같은 형태입니다.

#hostingforum.kr
php

use IntlTimeZone;



$timezone = IntlTimeZone::createUTC(9 * 60);

echo $timezone->getID() . "
"; // UTC+09:00



IntlTimeZone::__construct의 예제


IntlTimeZone::__construct를 사용하여 시간대 정보를 초기화하는 예제입니다.

#hostingforum.kr
php

use IntlTimeZone;



// 시간대 ID를 사용하여 시간대 정보를 초기화

$timezone1 = IntlTimeZone::createTimeZone('Asia/Seoul');

echo $timezone1->getID() . "
"; // Asia/Seoul



// UTC 오프셋을 사용하여 시간대 정보를 초기화

$timezone2 = IntlTimeZone::createUTC(9 * 60);

echo $timezone2->getID() . "
"; // UTC+09:00



// 시간대 ID를 사용하여 시간대 정보를 초기화하고, UTC 오프셋을 확인

$timezone3 = IntlTimeZone::createTimeZone('America/New_York');

echo $timezone3->getID() . "
"; // America/New_York

echo $timezone3->getOffset(new DateTime('2022-01-01')) . "
"; // -18000



IntlTimeZone::__construct는 시간대 정보를 초기화하는 데 사용할 수 있는 생성자입니다. 시간대 ID를 사용하거나 UTC 오프셋을 사용하여 시간대 정보를 초기화할 수 있습니다. IntlTimeZone::__construct를 사용하여 시간대 정보를 초기화하는 예제를 위에서 설명하였습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

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

검색

게시물 검색