Quick Reach
The timezone in PHP
The PHP date() function can be used to identify the timezone parameters.
The list of characters that can be used for PHP timezone is as given in the examples below with description:
PHP timezone identifier Example
The following example returns timezone identifier by using ‘e’ format character.
Experience this example online
1
2
3
4
5
|
<?php
echo date("e");
?>
|
Output: Returns Timezone identifier (added in PHP 5.1.0)
Timezone for daylight saving time example
Following example returns whether or not the zone is in daylight?
Experience this example online
1
2
3
4
5
|
<?php
echo date("I");
?>
|
Output: Whether or not the date is in daylight saving time
Example of returning difference to GMT hours
This example will return the difference with the GMT hours where this PHP script is running.
Experience this example online
1
2
3
4
5
|
<?php
echo date("O");
?>
|
Output: Difference to Greenwich time (GMT) in hours
Experience this example online
1
2
3
4
5
|
<?php
echo date("P");
?>
|
Output: Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)
PHP timezone abbreviation example
Following example returns timezone abbreviation by using ‘T’ character format of PHP date function.
Experience this example online
1
2
3
4
5
|
<?php
echo date("T");
?>
|
Output: Timezone abbreviation
Experience this example online
1
2
3
4
5
|
<?php
echo date("Z");
?>
|
Output: Timezone offset in seconds. The offset for timezones west of UTC is always negative and for those east of UTC is always positive.
Also read: PHP time | PHP mktime | getdate() function
Leave A Comment?