Introduction
In this article I explain two important timezone functions, date_default_timezone_get() and date_default_timezone_set() in PHP. Both functions are used for date purposes. I will first discusse the date_default_timezone_get() function and then the date_default_timezone_set() function.
Syntax
The date_default_timezone_get() function gets the default timezone. You can set the timezone in your project used for this but this function only reads the timezone environment variable in PHP 5.4. Such as:
|
date_default_timezone_get(void); |
This function returns string output.
Example
Getting the default timezone.
<?php
//get timezone
date_default_timezone_set('Europe/London');
//match your timezone
if (date_default_timezone_get())
{
echo 'date_default_timezone_set: ' . date_default_timezone_get() . "<br>";
}
//match your time with date
if (ini_get('date.timezone'))
{
echo 'date.timezone: ' . ini_get('date.timezone');
}
?>
Output
Example
Getting the abbreviation of a timezone.
<?php
//get timezone function


Join the conversation! Your thoughts help the community grow.