Share on Google+Share on Google+

date_timezone_set

Advertisement
The date_timezone_set alias DateTime::setTimezone function is used for setting the time zone for the DateTime object. It returns the modified DateTime. Learn how to define the date_timezone_set() in PHP language.

date_timezone_set() in PHP

date_timezone_set alias DateTime::setTimezone function is used for setting the time zone for the DateTime object. It returns the modified DateTime. 

Syntax on date_timezone_set() PHP

public DateTime DateTime::setTimezone ( DateTimeZone $timezone )
DateTime date_timezone_set ( DateTime $object , DateTimeZone $timezone )

Parameters of Date Timezone Setting in PHP

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

timezone - Desired time zone.

Example: Setting and getting DateTimeZone objects

<?php
date_default_timezone_set('India/Kolkata');

$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:

India/Kolkata
America/Los_Angeles

Advertisements

Advertisement

Posted on: August 27, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.