CakeFest 2024: The Official CakePHP Conference

DateTimeImmutable::setTimezone

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

DateTimeImmutable::setTimezoneタイムゾーンを設定する

説明

public DateTimeImmutable::setTimezone(DateTimeZone $timezone): DateTimeImmutable

新しいタイムゾーンを設定した、 新しい DateTimeImmutable オブジェクトを返します。

パラメータ

timezone

指定したいタイムゾーンを表す DateTimeZone オブジェクト。

戻り値

メソッドをチェインできるようにするため、 変更された新しい DateTimeImmutable オブジェクトを返します。 このメソッドをコールした際に指していた時刻は変わりません。

例1 DateTimeImmutable::setTimeZone() の例

オブジェクト指向型

<?php
$date
= new DateTimeImmutable('2000-01-01', new DateTimeZone('Pacific/Nauru'));
echo
$date->format('Y-m-d H:i:sP') . "\n";

$newDate = $date->setTimezone(new DateTimeZone('Pacific/Chatham'));
echo
$newDate->format('Y-m-d H:i:sP') . "\n";
?>

上の例の出力は以下となります。

2000-01-01 00:00:00+12:00
2000-01-01 01:45:00+13:45

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top