PHP 8.4.2 Released!

DateTime::setTimezone

date_timezone_set

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

DateTime::setTimezone -- date_timezone_setSets the time zone for the DateTime object

Descrizione

Stile orientato agli oggetti

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

Stile procedurale

Sets a new timezone for a DateTime object.

Like DateTimeImmutable::setTimezone() but works with DateTime.

The procedural version takes the DateTime object as its first argument.

Elenco dei parametri

oggetto

Solo per lo stile procedurale: Un oggetto DateTime restituito da date_create(). La funzione modifica questo oggetto.

timezone

A DateTimeZone object representing the desired time zone.

Valori restituiti

Returns the DateTime object for method chaining. The underlaying point-in-time is not changed when calling this method.

Esempi

Example #1 DateTime::setTimeZone() example

Stile orientato agli oggetti

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

Stile procedurale

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

I precedenti esempi visualizzeranno:

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

Vedere anche:

add a note

User Contributed Notes

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