Syntax:string gmdate ($format, $timestamp)
Parameters:The gmdate() function takes two parameter as above and described below:
- $format:is a required parameter that specifies the format of the returned date and time.
- $timestamp:Timestamp - optional parameter, if not included, current date and time will be used.
Return Value:This function returns a formatted date string on success and FALSE on failure and E_WARNING.The programs below illustrate the gmdate() function.
Program 1:
// PHP program to illustrate the gmdate function
// display date 25 June 2018 23:21:50
echo
gmdate
(
"M d YH: i: s"
,
mktime
(23, 21, 50, 6, 25, 2018)).
""
;
// display the date of the World Wide Web Consortium
// 2018-06-25T23: 21: 50 + 00: 00
echo
gmdate
(DATE_W3C,
mktime
(23, 21, 50, 6, 25, 2018)).
""
;
// display date in ISO-8601 format
echo
gmdate
(DATE_ISO8601,
mktime
(23, 21, 50, 6, 25, 2018)).
""
;
?>
Exit:Jun 25 2018 23:21:50 2018-06-25T23: 21: 50 + 00: 00 2018-06-25T23: 21: 50 + 0000
Program 2:By passing one parameter, it will return the current local time (time()).
/ / PHP program to illustrate the gmdate function
// display the current date and time
// 28 June 2018 14:52:50
echo
gmdate
(
"M d YH: i: s"
).
""
;
// display the date of the World Wide Web Consortium
echo
gmdate
(DATE_W3C).
""
;
// display date in ISO-8601 format
echo
gmdate
(DATE_ISO8601).
""
;
?>
Exit:Jun 29 2018 06:32:34 2018-06-29T06: 32: 34 + 00: 00 2018-06-29T06: 32: 34 + 0000
Similar article: - PHP | Date and time
- PHP | time function()
Link: http://php.net/manual/en/function.gmdate.php