라이브러리

[PHP] IntlTimeZone::fromDateTimeZone - DateTimeZone에서 시간대 객체를 생성합니다.




IntlTimeZone::fromDateTimeZone

`IntlTimeZone::fromDateTimeZone`는 DateTimeZone 객체를 IntlTimeZone 객체로 변환하는 메서드입니다. 이 메서드는 PHP 7.2 이상에서 사용할 수 있습니다.

사용법

IntlTimeZone::fromDateTimeZone 메서드는 다음과 같이 사용할 수 있습니다.

#hostingforum.kr
php

 IntlTimeZone::fromDateTimeZone(DateTimeZone $timezone);



* `$timezone` : DateTimeZone 객체

예제

아래 예제는 `IntlTimeZone::fromDateTimeZone` 메서드를 사용하여 DateTimeZone 객체를 IntlTimeZone 객체로 변환하는 방법을 보여줍니다.

#hostingforum.kr
php

// DateTimeZone 객체 생성

$timezone = new DateTimeZone('Asia/Seoul');



// IntlTimeZone 객체로 변환

$intl_timezone = IntlTimeZone::fromDateTimeZone($timezone);



// IntlTimeZone 객체의 정보 출력

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

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



IntlTimeZone 객체의 메서드

IntlTimeZone 객체는 다음과 같은 메서드를 제공합니다.

* `getID()`: IntlTimeZone 객체의 ID를 반환합니다.
* `getOffset(DateTime $dateTime)`: DateTime 객체의 시간대 오프셋을 반환합니다.
* `getRawOffset()`: IntlTimeZone 객체의 기본 시간대 오프셋을 반환합니다.
* `getTransitionDateTime()`: IntlTimeZone 객체의 시간대 전환 날짜를 반환합니다.

IntlTimeZone 객체의 사용

IntlTimeZone 객체는 다음과 같은 용도로 사용할 수 있습니다.

* 시간대 변환: IntlTimeZone 객체를 사용하여 DateTime 객체의 시간대 오프셋을 변환할 수 있습니다.
* 시간대 정보 추출: IntlTimeZone 객체를 사용하여 시간대 ID, 기본 시간대 오프셋, 시간대 전환 날짜를 추출할 수 있습니다.

IntlTimeZone 객체의 예제

아래 예제는 IntlTimeZone 객체의 메서드를 사용하여 시간대 정보를 추출하고 변환하는 방법을 보여줍니다.

#hostingforum.kr
php

// IntlTimeZone 객체 생성

$timezone = IntlTimeZone::fromDateTimeZone(new DateTimeZone('Asia/Seoul'));



// 시간대 ID 출력

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



// 기본 시간대 오프셋 출력

echo $timezone->getRawOffset() . "
"; // 32400



// 시간대 오프셋 출력

$dateTime = new DateTime('2022-01-01');

echo $timezone->getOffset($dateTime) . "
"; // 32400



// 시간대 전환 날짜 출력

echo $timezone->getTransitionDateTime() . "
"; // 2022-01-01 00:00:00



IntlTimeZone::fromDateTimeZone 메서드는 DateTimeZone 객체를 IntlTimeZone 객체로 변환하는 데 사용할 수 있습니다. IntlTimeZone 객체는 시간대 정보를 추출하고 변환하는 데 사용할 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

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

검색

게시물 검색