Thursday, December 18, 2025
HomeLanguagesPHP | date_timezone_get() Function

PHP | date_timezone_get() Function

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);
?>


Output:

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();
?>


Output:

Asia/Kolkata

Related Articles:

Reference: http://php.net/manual/en/datetime.gettimezone.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32455 POSTS0 COMMENTS
Milvus
108 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11958 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12036 POSTS0 COMMENTS
Shaida Kate Naidoo
6958 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6910 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS