w3resource

PHP: date_default_ timezone_get() function

Description

The date_default_timezone_get() is used to get the default timezone, used by all date/time functions in a script.

Version:

(PHP 4 and above)

Syntax:

date_default_timezone_get()

Return value:

A string.

Value Type: String.

Example:

<?php
echo(date_default_timezone_get());
?>

Output:

UTC

View the example of in the browser

See also

PHP Function Reference

Previous: checkdate
Next: date_default_ timezone_set



PHP: Tips of the Day

Getting all defined constants

To get all defined constants including those created by PHP use the get_defined_constants function:

Example:

<?php
$constants = get_defined_constants();
var_dump($constants); // pretty large list

Output:

array(2250) {
  ["E_ERROR"]=>
  int(1)
  ["E_RECOVERABLE_ERROR"]=>
  int(4096)
  ["E_WARNING"]=>
  .....
  .....
  resource(1) of type (stream)
  ["STDOUT"]=>
  resource(2) of type (stream)
  ["STDERR"]=>
  resource(3) of type (stream)
}

To get only those constants that were defined by your app call the function at the beginning and at the end of your script (normally after the bootstrap process):

<?php
$constants = get_defined_constants();
define("HELLO", "hello");
define("WORLD", "world");
$new_constants = get_defined_constants();
$myconstants = array_diff_assoc($new_constants, $constants);
var_export($myconstants);

Output:

array (
  'HELLO' => 'hello',
  'WORLD' => 'world',
)

It's sometimes useful for debugging