date_default_timezone_get


 

date_default_timezone_get

This example will tell you about getting date default timezone in PHP.

This example will tell you about getting date default timezone in PHP.

 date_default_timezone_get

date_default_timezone_get  function is used for retrieving the default timezone used by all date/time functions in a script. It returns a string. 

Description

string date_default_timezone_get ( void )

This function returns the default timezone in order of preference like:

First reading the timezone set using the date_default_timezone_set() function (if any)

Reading the timezone environment variable (if non empty)

Reading the value of the date.timezone ini option (if set)

Querying the host operating system (if supported and allowed by the OS)

If none of the above succeed, date_default_timezone_get will return a default timezone of UTC.

Examples

<?php
date_default_timezone_set('India/Kolkata');

if (date_default_timezone_get()) {
echo 'date_default_timezone_set: ' . date_default_timezone_get() . '<br />';
}

if (ini_get('date.timezone')) {
echo 'date.timezone: ' . ini_get('date.timezone');
}

?>

The above example will output something similar to:

date_default_timezone_set: India/Kolkata

date.timezone: India/Kolkata

Ads