PHP 8.6.0 Beta 1 is available for testing

DateTimeImmutable::setTimezone

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

DateTimeImmutable::setTimezoneEstablece la zona horaria

Descripción

#[\NoDiscard(message: "as DateTimeImmutable::setTimezone() does not modify the object itself")]
public function DateTimeImmutable::setTimezone(DateTimeZone $timezone): DateTimeImmutable

Devuelve un nuevo objeto DateTimeImmutable con una nueva zona horaria establecida.

Parámetros

timezone

Un objeto DateTimeZone que representa la zona horaria deseada.

Valores devueltos

Devuelve un nuevo objeto DateTimeImmutable modificado para encadenar métodos. El instante subyacente no se modifica al llamar a este método.

Ejemplos

Ejemplo #1 Ejemplo de DateTimeImmutable::setTimeZone()

Estilo orientado a objetos

<?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";
?>

El ejemplo anterior mostrará:

2000年01月01日 00:00:00+12:00
2000年01月01日 01:45:00+13:45

Véase también

Found A Problem?

Learn How To Improve This PageSubmit a Pull RequestReport a Bug
+add a note

User Contributed Notes

There are no user contributed notes for this page.

AltStyle によって変換されたページ (->オリジナル) /