Tutorials Point


  Learning PHP
  Advanced PHP
  PHP Function Reference
  PHP Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

PHP Function timezone_open()


previous

Advertisements

Syntax

timezone_open ( $timezone )

DateTimeZone::__construct ( $timezone );

Definition and Usage

These functions return new DateTimeZone object.

The above two functions are equivalent and any of the functions can be used as shown below in the example.

Paramters

ParameterDescription
timezoneTime zone identifier as full name (e.g. Europe/Prague) or abbreviation (e.g. CET).

Return Value

Returns DateTimeZone object on success or FALSE on failure.

Example

Following is the usage of this function:

<?php
 $dateSrc = '2007-04-19 12:50 GMT';
   $dateTime = date_create( $dateSrc);
   $DateTimeZone = timezone_open ( 'America/Chicago' );
   date_timezone_set( $dateTime, $DateTimeZone );
   $NewDateTimeZone = date_timezone_get($dateTime);
   echo 'New timeZone is '. timezone_name_get($NewDateTimeZone);
   echo "\n";

   # Using second function.
   $dateTime = new DateTime($dateSrc);
   $DateTimeZone = new DateTimeZone( 'America/Chicago' );
   $dateTime->setTimezone( $DateTimeZone );
   $NewDateTimeZone = $dateTime->getTimezone ();
   echo 'New timeZone is '. timezone_name_get ($NewDateTimeZone);
?>

This will produce following result:

New timeZone is America/Chicago
New timeZone is America/Chicago

previous Printer Friendly

Advertisements


  

Advertisements