• PHP Video Tutorials

PHP - Function date_default_timezone_get()



Syntax

string date_default_timezone_get ( void );

Definition and Usage

It gets the default timezone used by all date/time functions in a script.

This functions returns the default timezone, using the following "guess" order −

  • The timezone set using the date_default_timezone_set() function (if any)

  • The TZ environment variable (if non empty)

  • The date.timezone in option (if set)

  • "magical" guess (if the operating system supports it)

  • If none of the above options succeeds, return UTC

Parameters

Sr.No Parameter & Description
1

void

NA 

Return Value

Returns a string.

Example

Following is the usage of this function −

<?php
   echo "Old time zone is ". date_default_timezone_get();
   $timeZone = 'America/Costa_Rica';
   
   if( date_default_timezone_set( $timeZone) ){
      # Now get this time zone.
      echo "New time zone is ". date_default_timezone_get();
   }
?> 

This will produce the following result −

Old time zone is America/Denver
New time zone is America/Costa_Rica
php_function_reference.htm
Advertisements