DateTime
PHP Manual

DateTime::setTimezone

(PHP 5 >= 5.2.0)

DateTime::setTimezoneSets the time zone for the DateTime object

Descrierea

Stil obiect-orientat

public DateTime DateTime::setTimezone ( DateTimeZone $timezone )

Stil procedural

Parametri

object

Doar stilul procedural: Un obiect DateTime întors de date_create(). Funcția modifică acest obiect.

timezone

A DateTimeZone object representing the desired time zone.

Valorile întoarse

Întoarce obiectul DateTime modificat sau FALSE în cazul eșecului.

Istoria schimbărilor

Versiunea Descriere
5.3.0 Changed the return value from NULL to DateTime.

Exemple

Example #1 DateTime::setTimeZone() example

Stil obiect-orientat

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

Stil procedural

<?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($datetimezone_open('Pacific/Chatham'));
echo 
date_format($date'Y-m-d H:i:sP') . "\n";
?>

Exemplele de mai sus vor afișa:

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

Vedeți de asemenea


DateTime
PHP Manual