English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Manuel des fonctions Date & Time PHP
La fonction gmdate() formate un GMT/Date et heure UTC
gmdate()La fonction accepte une chaîne de format en tant que paramètre pour spécifier le format de formatage local GMT/Date UTC/Heure
Il est complètement identique à la fonction date(), à l'exception que le temps retourné est le fuseau horaire Greenwich (GMT). Par exemple, en Chine (GMT +0800) Exécuter le programme suivant, la première ligne affiche “Jan 01 2000 00:00:00” et la deuxième ligne affiche “Dec 31 1999 16:00:00.
gmdate($format, $timestamp)
Number | Parameters and descriptions |
---|---|
1 | format (required) This is a format string that specifies the format of the date string you want to output. |
2 | timestamp (optional) This is an integer value representing the timestamp of the required date |
PHP gmdate() function returns the current local time in the specified format/Date.
This function was originally introduced in PHP version4introduced in PHP version 5 and is available in all later versions.
Try the following demonstrationgmdate()Usage of the function-
<?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 prints the sunrise using the result date/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 a 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 \ echo gmdate('l dS of F Y h:i:s A'); echo \ ?>Test to see‹/›
This produces the following result-
Wednesday Wednesday 13th of May 2020 05:57:30 PM