• PHP Video Tutorials

PHP - Function date_default_timezone_set()



Syntax

bool date_default_timezone_set ( string $timezone_identifier )

Definition and Usage

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

Parameters

Sr.No Parameter & Description
1

timezone_identifier

A valid timezone string

Return Value

It returns FALSE if the timezone_identifier isn't valid, or TRUE otherwise.

Example

Following is the usage of this function −

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

This will produce the following result −

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