English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Руководство по функциям даты и времени PHP
Функция gmdate() форматирует дату/время GMT/UTC
gmdate()Функция принимает строку формата в качестве параметра для форматирования локальной даты/времени GMT/UTC.
Полностью такой же, как функция date(), за исключением того, что возвращаемое время — это время по среднеевропейскому времени (GMT). Например, когда в Китае (GMT +0800) запущен следующий скрипт, первое строка показывает «Jan 01 2000 00:00:00», а вторая строка показывает «Dec 31 1999 16:00:00».
gmdate($format, $timestamp)
Номер | Параметры и описание |
---|---|
1 | format (обязателен) Это форматированная строка, которая определяет формат строки даты, которую вы хотите вывести. |
2 | timestamp (optional) This is an integer value representing the timestamp of the required date |
The PHP gmdate() function returns the current local time/date in the specified format.
This function was initially introduced in PHP version 4 and can be used in all higher versions.
Try the following demonstrationgmdate()Function usage-
<?php $date = gmdate("D M d Y"); print("Date: ". $date); ?>Test to see‹/›
Output result
Date: Fri May 08 2020
The following example uses this function to format the current date and use the result date to print sunrise/sunset information-
<?php $date = gmdate("H:i:s"); $sun_info = date_sun_info($date, 20.5937, 78.9629); print_r($sun_info); ?>Test to see‹/›
Output result
Array ( [sunrise] => 4818 [sunset] => 44087 [transit] => 24453 [civil_twilight_begin] => 3381 [civil_twilight_end] => 45524 [nautical_twilight_begin] => 1729 [nautical_twilight_end] => 47176 [astronomical_twilight_begin] => 98 [astronomical_twilight_end] => 48807 )
Now, call the function by passing the timestampgmdate()Function-
<?php $ts = 1022555568; $date = gmdate("D M d Y", $ts); print($date); ?>Test to see‹/›
Output result
Tue May 28 2002
<?php date_default_timezone_set('UTC'); echo gmdate("l"); echo "\n"; echo gmdate('l dS of F Y h:i:s A'); echo "\n"; ?>Test to see‹/›
This produces the following result-
Wednesday Wednesday 13th of May 2020 05:57:30 PM