English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutoriel PHP de base

Tutoriel PHP avancé

PHP & MySQL

Manuel de référence PHP

Utilisation et exemples de la fonction gmdate() PHP

Manuel des fonctions Date & Time PHP

La fonction gmdate() formate un GMT/Date et heure UTC

Définition et utilisation

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.

Syntax

gmdate($format, $timestamp)

Parameter

NumberParameters 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

Return value

PHP gmdate() function returns the current local time in the specified format/Date.

PHP version

This function was originally introduced in PHP version4introduced in PHP version 5 and is available in all later versions.

Online example

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

Online example

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
)

Online example

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

Online example

<?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