The date_timezone_get() function is an inbuilt function in PHP which is used to return time zone relative to given DateTime. This function returns a DateTimeZone object on success or False on failure.
Syntax:
- Procedural style:
date_timezone_get( $object )
- Object oriented style:
DateTime::getTimezone( void ) DateTimeImmutable::getTimezone( void ) DateTimeInterface::getTimezone( void )
Parameters: This function accepts single parameter $object which is mandatory in procedural style. It is used to specify the DateTime object which is returned by the date_create() function. The object oriented style does not require any parameter.
Return Value: This function returns a DateTimeZone object on success or False on failure.
Below programs illustrate the date_timezone_get() function in PHP:
Program 1:
<?php // Create DateTime object $date = date_create(null, timezone_open('Asia/Kolkata')); // Return the timezone of given DateTime $time_zone = date_timezone_get($date); // Return the DateTimeZone object echo timezone_name_get($time_zone); ?> |
Asia/Kolkata
Program 2:
<?php // Create DateTime object using DateTimeZone $date = new DateTime(null, new DateTimeZone('Asia/Kolkata')); // Return the timezone of given DateTime $time_zone = $date->getTimezone(); // Return the DateTimeZone object echo $time_zone->getName(); ?> |
Asia/Kolkata
Related Articles:
Reference: http://php.net/manual/en/datetime.gettimezone.php
Recommended Posts:
- How to Check a Function is a Generator Function or not using JavaScript ?
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- D3.js | d3.hcl() Function
- p5.js | nf() Function
- p5.js | nfc() function
- CSS | rgb() Function
- p5.js | pow() function
- D3.js | d3.rgb() Function
- p5.js | day() function
- CSS | url() Function
- D3.js | d3.lab() Function
- D3.js | d3.map.set() Function
- p5.js | sq() function
- PHP | ord() Function
- PHP | pow( ) Function
- p5.js | nfp() Function
- p5.js | nfs() Function
- p5.js | abs() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

