English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Date & Time Function Manual
A função date_timezone_get() retorna o fuso horário em relação ao DateTime fornecido
A função date_timezone_get() é um alias de DateTime::getTimezone. Ela aceita um objeto DateTime como parâmetro e retorna o fuso horário em relação à data fornecida./The timezone object of the time (object).
date_timezone_get($object)
Serial number | Parameters and descriptions |
---|---|
1 | object (required) This means you need the DateTime object for the timezone. |
This function returns a DateTimeZone object. If it fails, it returns a boolean valuefalse.
This function was initially introduced in PHP version5.2.1introduced in and can be used in all higher versions.
The following isdate_timezone_get()Example of function-
<?php $date = date_create("25-09-1989"); $res = date_timezone_get($date); $timeZone_name = timezone_name_get($res); print("Timezone: ").$timeZone_name; ?>Test and see‹/›
Output result
Timezone: UTC
The following example sets the timezone and usesdate_timezone_get()The function retrieves it.
<?php $tz = new DateTimeZone("Indian/Mahe"); $date = date_create("25-09-1989", $tz); $res = date_timezone_get($date); print_r($res); ?>Test and see‹/›
Output result
DateTimeZone Object ( [timezone_type] => 3 [timezone] => Indian/Mahe )
Thisdate_timezone_get()The function just gives you the timezone object, you can get its nameUse timezone_name_get() -
<?php $tz = new DateTimeZone("Indian/Mahe"); $date = date_create("25-09-1989", $tz); $res = date_timezone_get($date); $timeZone_name = timezone_name_get($res); print("Default timezone: ").$timeZone_name; ?>Test and see‹/›
Output result
Default timezone: Indian/Mahe
Change the default timezone
<?php echo "The old timezone is ". date_default_timezone_get(); $timeZone = 'Asia/Shanghai'; if(date_default_timezone_set($timeZone)){ #Now we get this timezone. echo "The new timezone is ". date_default_timezone_get(); } ?>Test and see‹/›
Output result:
The old timezone is UTC The new timezone is Asia/Shanghai