(PHP 5 >= 5.2.0, PHP 7)
DateTime::setTimezone -- date_timezone_set — Sets the time zone for the DateTime object
객체 기반 형식
절차식 형식
object
Procedural style only: A DateTime object returned by date_create(). The function modifies this object.
timezone
A DateTimeZone object representing the desired time zone.
메소드 체이닝을 위한 DateTime 객체를 반환합니다.실패 시 FALSE
를 반환합니다.
버전 | 설명 |
---|---|
5.3.0 | 반환값을 NULL 에서
DateTime으로 변경. |
Example #1 DateTime::setTimeZone() example
객체 기반 형식
<?php
$date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
echo $date->format('Y-m-d H:i:sP') . "\n";
$date->setTimezone(new DateTimeZone('Pacific/Chatham'));
echo $date->format('Y-m-d H:i:sP') . "\n";
?>
절차식 형식
<?php
$date = date_create('2000-01-01', timezone_open('Pacific/Nauru'));
echo date_format($date, 'Y-m-d H:i:sP') . "\n";
date_timezone_set($date, timezone_open('Pacific/Chatham'));
echo date_format($date, 'Y-m-d H:i:sP') . "\n";
?>
위 예제들의 출력:
2000-01-01 00:00:00+12:00 2000-01-01 01:45:00+13:45