PHP | DateTimeImmutable::setTimezone() Function Last Updated : 11 Oct, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The DateTimeImmutable::setTimezone() function is an inbuilt function in PHP which is used to set the time zone for the created DateTimeImmutable object. This function returns the DateTimeImmutable object or False on failure. Syntax: DateTimeImmutable::setTimezone ( TimeZone ) Parameters: This function accepts one parameters which is illustrated below:- TimeZone: This parameter is used to set the DateTimeZone object representing the desired time zone. Return Values: This function returns the DateTimeImmutable object on success or False on failure. Below programs illustrate the DateTimeImmutable::setTimezone() function : Program 1 : php <?php // PHP program to illustrate DateTimeImmutable::setTimezone() // function // Creating a DateTimeImmutable() object $DateTimeImmutable = new DateTimeImmutable('2019-10-07', new DateTimeZone('Asia/Kolkata')); // Getting the above datetime format echo $DateTimeImmutable->format('d-m-Y H:i:sP') . "\n"; // Calling the DateTimeImmutable::setTimezone() function $a = $DateTimeImmutable->setTimezone(new DateTimeZone('Asia/Singapore')); // Getting a new DateTimeImmutable object echo $a->format('d-m-Y H:i:sP'); ?> Output: 07-10-2019 00:00:00+05:30 07-10-2019 02:30:00+08:00 Program 2: php <?php // PHP program to illustrate DateTimeImmutable::setTimezone() // function // Creating a DateTimeImmutable() object $DateTimeImmutable = new DateTimeImmutable('2019-10-07'); // Getting the above datetime format echo $DateTimeImmutable->format('d-m-Y H:i:sP') . "\n"; // Calling the DateTimeImmutable::setTimezone() function $a = $DateTimeImmutable->setTimezone(new DateTimeZone('Asia/Singapore')); // Getting a new DateTimeImmutable object echo $a->format('d-m-Y H:i:sP'); ?> Output: 07-10-2019 00:00:00+00:00 07-10-2019 08:00:00+08:00 Reference: https://devdocs.io/php/datetimeimmutable.settimezone Comment More infoAdvertise with us Next Article PHP | date_timezone_set() Function K Kanchan_Ray Follow Improve Article Tags : Web Technologies PHP PHP-date-time PHP-function Similar Reads PHP | DateTimeImmutable setDate() Function The DateTimeImmutable::setDate() function is an inbuilt function in PHP which is used to set a new date in the created DateTimeImmutable object. Syntax: DateTimeImmutable DateTimeImmutable::setDate( int $year, int $month, int $day ) Parameters: This function accepts three parameters as mentioned abo 2 min read PHP | DateTimeImmutable setTimestamp() Function The DateTimeImmutable::setTimestamp() function is an inbuilt function in PHP which is used to set the date and time based on an Unix timestamp. Syntax: DateTimeImmutable DateTimeImmutable::setTimestamp( int $unixtimestamp ) Parameters: This function accepts single parameter $unixtimestamp which is u 1 min read PHP | DateTimeImmutable setISODate() Function The DateTimeImmutable::setISODate() function is an inbuilt function in PHP which is used to sets the ISO (International Organization for Standardization ) date into the created DateTimeImmutable object. This function sets the date according to the ISO 8601 standard, using weeks and day offsets rathe 2 min read PHP | DateTimeImmutable::sub() Function The DateTimeImmutable::sub() function is an inbuilt function in PHP which is used to subtract a number of days, months, years, hours, minutes and seconds from a created DateTimeImmutable object. Syntax: DateTimeImmutable::sub( interval ) Parameters: This function accepts a parameter interval which i 2 min read PHP | date_timezone_set() Function The date_timezone_set() function is an inbuilt function in PHP which is used to sets the time zone for the DateTime object. This function returns the DateTime object or False on failure. Syntax: Procedural style: date_timezone_set( $object, $timezone ) Object oriented style: DateTime::setTimezone( $ 2 min read PHP | date_default_timezone_set() Function The date_default_timezone_set() function is an inbuilt function in PHP which is used to set the default timezone used by all date/time functions in a script. This function returns False if the timezone is not valid, or True otherwise. Syntax: bool date_default_timezone_set( $timezone_identifier ) Pa 2 min read Like