
IntlDateFormatter 클래스의 timeZone을 설정하는 방법은 다음과 같습니다.
1. IntlDateFormatter 클래스를 생성합니다.
2. locale을 설정합니다. (예: $formatter = new IntlDateFormatter('ko_KR');)
3. timeZone을 설정합니다. (예: $formatter->setTimeZone('Asia/Seoul');)
timeZone이 설정된 후에 날짜 형식을 변환할 때 timeZone이 적용됩니다.
IntlDateFormatter::setTimeZone($timeZone);이렇게 timeZone을 설정한 후에 IntlDateFormatter::format($date);으로 날짜 형식을 변환하면 timeZone이 적용됩니다.
예제:
#hostingforum.kr
php
$formatter = new IntlDateFormatter('ko_KR');
$formatter->setTimeZone('Asia/Seoul');
$date = new DateTime('2022-01-01 00:00:00', new DateTimeZone('UTC'));
echo $formatter->format($date); // 2022-01-01 00:00:00
위 예제에서 UTC 시간을 Asia/Seoul 시간으로 변환한 것을 볼 수 있습니다.
2025-03-25 15:14