downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DateTime::sub> <DateTime::setTimestamp
Last updated: Fri, 20 Nov 2009

view this page in

DateTime::setTimezone

(PHP 5 >= 5.2.0)

DateTime::setTimezoneSets the time zone for the DateTime object

Description

public DateTime DateTime::setTimezone ( DateTimeZone $timezone )

Parameters

object

Procedural style only: A DateTime object returned by date_create()

timezone

Desired time zone.

Return Values

Returns the modified DateTime.

Changelog

Version Description
5.3.0 Changed the return value from NULL to DateTime.

Examples

Example #1 Setting and getting DateTimeZone objects

<?php
date_default_timezone_set
('Europe/London');

$datetime = new DateTime('2008-08-03 12:35:23');
echo 
$datetime->getTimezone()->getName() . "\n";

$datetime = new DateTime('2008-08-03 12:35:23');
$la_time = new DateTimeZone('America/Los_Angeles');
$datetime->setTimezone($la_time);
echo 
$datetime->getTimezone()->getName();
?>

The above example will output:

Europe/London
America/Los_Angeles

See Also



add a note add a note User Contributed Notes
DateTime::setTimezone
dan dot morin at gmail dot com
26-Jun-2009 04:56
In my setup setTimezone() does modify the date, as well as the TZ.

Code:

<?php
$dt_obj
= new DateTime('2009-06-25 12:00:00');
echo
$dt_obj->format(DATE_RFC822) . "\n";
$dt_obj->setTimezone(new DateTimeZone('GMT'));
echo
$dt_obj->format(DATE_RFC822);
?>

Output:
Thu, 25 Jun 09 12:00:00 -0400
Thu, 25 Jun 09 16:00:00 +0000
sht dot alien at gmx dot net
17-Jun-2009 01:13
Btw: setTimezone() does NOT modify the date, just the TZ. I tested this just to make sure 'cause the documentation doesn't tell.

DateTime::sub> <DateTime::setTimestamp
Last updated: Fri, 20 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites