date_timezone_set


 

date_timezone_set

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.

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

Ads