gmdate


time apg

RETURNS the formated local time or date related to GMT/UTC where:

GMT, Greenwich Mean Time and
UTC, Coordinated Universal Time.



<?php

str gmdate 
str $format int|null $timestamp null )


$format The format of outpitted date
                 
(SEE the below TABLE)
                 
In additionsome constants may be used
                 
which have recurring values
                 
(SEE the below TABLE)

$timestamp The UNIX timestamp:
                      
The current local time, if not given.
                      
In other words it uses the default provided 
                      by the time 
function.
                      
?>

 $format 

RECOGNIZED CHARACTERS
FORMAT CHARACTER Description Example returned values
Day
d Day of the month, 2 digits with leading zeros 01 to 31
D A textual representation of a day, three letters Mon through Sun
j Day of the month without leading zeros 1 to 31
l A full textual representation of the day of the week Sunday through Saturday
N ISO-8601 numeric representation of the day of the week
Since PHP 5.1.0
1 (for Monday) through 7 (for Sunday)
S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th.
Works well with j
w Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday)
z The day of the year (starting from 0) 0 through 365
Week
W ISO-8601 week number of year, weeks starting on Monday Example:
42 (the 42nd week in the year)
Month
F A full textual representation of a month, such as January or March January through December
m Numeric representation of a month, with leading zeros 01 through 12
M A short textual representation of a month, three letters Jan through Dec
n Numeric representation of a month, without leading zeros 1 through 12
t Number of days in the given month 28 through 31
Year
L Whether it's a leap year 1 if it is a leap year, 0 otherwise.
o ISO-8601 week-numbering year.
This has the same value as Y,
except that if the ISO week number (W) belongs to the previous or next year, that year is used instead.
Since PHP 5.1.0
Examples:
1999 or 2018
Y A full numeric representation of a year, 4 digits Examples:
1999 or 2018
y A two digit representation of a year Examples:
99 or 18
Time
a Lowercase Ante meridiem and Post meridiem am or pm
A Uppercase Ante meridiem and Post meridiem AM or PM
B Swatch Internet time 000 through 999
g 12-hour format of an hour without leading zeros 1 through 12
G 24-hour format of an hour without leading zeros 0 through 23
h 12-hour format of an hour with leading zeros 01 through 12
H 24-hour format of an hour with leading zeros 00 through 23
i Minutes with leading zeros 00 to 59
s Seconds, with leading zeros 00 through 59
u Microseconds - Since PHP 5.2.2.
Note that date will always generate 000000
since it takes an integer parameter,
whereas DateTime::format does
support microseconds if DateTime created with microseconds.
Example: 654321
v Milliseconds - Since PHP 7.0.0.
Same note applies as for u.
Example: 654
Timezone
e Timezone identifier
Since PHP 5.1.0
Examples: UTC, GMT, Atlantic/Azores
I (capital i) Whether or not the date is in Daylight Saving Time 1 if DST, 0 if not DST.
O Difference to Greenwich time (GMT) in hours Example: +0200
P Difference to Greenwich time (GMT)
with colon between hours and minutes.
Since PHP 5.1.3
Example: +02:00
T Timezone abbreviation Examples: EST, MDT ...
Z Timezone offset in seconds.
The offset for timezones west of UTC
is always negative,
and for those east of UTC is always positive.
-43200 through 50400
Full Date/Time
c ISO 8601 date (added in PHP 5) 2004-02-12T15:19:21+00:00
r RFC 2822 formatted date Example:
Thu, 21 Dec 2000 16:01:07 +0200
U Seconds since the Unix Epoch:
January 1 1970 00:00:00 GMT
See also the function time
ed48


Alternatively we can use the values displayed in the next table:

FORMAT CHARACTER USE TIMESTAMP PROVIDED BY
H gmdate("H") time()
i gmdate("i")
s gmdate("s")
n gdate("n")
j gmdate("j")
Y gmdate("Y")
ed48


 PREDEFINED DATE CONSTANTS 

FORMAT DATES
Usual Interface DateTimeInterface
STRING
DESCRIPTION
DATE_ATOM DateTimeInterface::ATOM
Y-m-d\TH:i:sP
Atom:
2018-08-15T15:52:01+00:00
DATE_COOKIE DateTimeInterface::COOKIE
l, d-M-Y H:i:s T
HTTP Cookies:
Monday, 15-Aug-2018 15:52:01 UTC
* DATE_ISO8601 DateTimeInterface::ISO8601
Y-m-d\TH:i:sO
ISO-8601:
2018-08-15T15:52:01+0000
DATE_RFC822 DateTimeInterface::RFC822
D, d M y H:i:s O
RFC 822:
Mon, 15 Aug 18 15:52:01 +0000
DATE_RFC850 DateTimeInterface::RFC850
l, d-M-y H:i:s T
RFC 850:
Monday, 15-Aug-18 15:52:01 UTC
DATE_RFC1036 DateTimeInterface::RFC1036
D, d M y H:i:s O
RFC 1036:
Mon, 15 Aug 18 15:52:01 +0000
DATE_RFC1123 DateTimeInterface::RFC1123
D, d M Y H:i:s O
RFC 1123:
Mon, 15 Aug 2018 15:52:01 +0000
DATE_RFC2822 DateTimeInterface::RFC2822
D, d M Y H:i:s O
RFC 2822:
Mon, 15 Aug 2018 15:52:01 +0000
DATE_RFC7231 DateTimeInterface::RFC7231
D, d M Y H:i:s \G\M\T
RFC 7231:
Mon, 15 Aug 2018 15:52:01 GMT
DATE_RFC3339 DateTimeInterface::RFC3339
Y-m-d\TH:i:sP
Same as DATE_ATOM
Since PHP 5.1.3
DATE_RFC3339_EXTENDED DateTimeInterface::RFC3339_EXTENDED
Y-m-d\TH:i:s.vP
RFC 3339 EXTENDED format
Since PHP 7.0.0
2018-08-15T15:52:01.000+00:00
DATE_RSS DateTimeInterface::RSS
D, d M Y H:i:s O
RSS:
Mon, 15 Aug 2018 15:52:01 +0000
DATE_W3C DateTimeInterface::W3C
Y-m-d\TH:i:sP
World Wide Web Consortium:
2018-08-15T15:52:01+00:00
ed48

* This format is not compatible with ISO-8601, but is left this way for backward compatibility reasons.

Use DATE_ATOM or DateTime::ATOM for compatibility with ISO-8601 instead.


 $timestamp 


The related timestamp to be considered.





See also:

 date_create_from_format  for related formats.

This function is identical to the  date  function, except that the time returned is the GMT, Greenwich Mean Time.

Since PHP 8.0.0 $timestamp is nullable.



  1 EXERCISE   

<?php

// CURRENT TIMESTAMP

$gmdate01 gmdate(DateTimeInterface::RFC850);

echo 
$gmdate01

?>

  2 EXERCISE   

<?php

$str_tz 
'Asia/Tokyo';

$tzok date_default_timezone_set($str_tz);

// If the timezone is not assigned, UTC will be considered

$gmdatef_01 gmdate("l F d Y h:i:s A");

// If $int_timestamp, is not provided, 
// the current value of time() will be considered

$ts_now time(); 
// CURRENT TIMESTAMP

$gmdatef_02 =  gmdate("l F d Y H:i:s"$ts_now);

echo 
'gmdate("l F d Y h:i A")<br><br>' $gmdatef_01;

echo 
'<br><br><br>gmdate("l F d Y H:i:s", time())<br><br>' $gmdatef_02 '<br>';

?> 

  3 EXERCISE   

<?php

$str_tz 
'UTC';

$tzok date_default_timezone_set($str_tz);

$ts_zero 0
// VALUE OF TIMESTAMP EQUAL TO ZERO

$datef_03 =  gmdate("l F d Y H:i:s"$ts_zero);

echo 
'<br><br><br>gmdate("l F d Y H:i:s", time())<br><br>' $datef_03 '<br>';

?> 

  4 EXERCISE   

<?php 

$str_tz 
'UTC'

$tzok date_default_timezone_set($str_tz); 

$ts_ant = -112345678
// VALUE OF TIMESTAMP LESS THAN ZERO

$datef_04 =  gmdate("l F d Y H:i:s"$ts_ant); 

echo 
'<br><br><br>gdate("l F d Y H:i:s", 
                time())<br><br>' 
$datef_04 '<br>';

?> 

  5 EXERCISE   

<?php 

$arrid05 
= [ "H" => "GMT hour"
               
"i" => "GMT minute"
               
"s" => "GMT second"
               
"n" => "Month"
               
"i" => "Minutes"
               
"j" => "Day"
               
"Y" => "Year" ];

foreach(
$arrid05 as $vl05 => $v05)  
{  
    echo 
'&nbsp;&nbsp;[' $vl05 ']&nbsp;&nbsp;' 
    
gmdate($vl05) . '&nbsp;&nbsp;=>&nbsp;' $v05 '<br>';  
}  

echo 
'<br><br>';  

?> 

  6 EXERCISE   

<?php


$datef06a 
= [ 'DATE_ATOM' => DATE_ATOM
               
'DATE_COOKIE' => DATE_COOKIE
               
'DATE_ISO8601' => DATE_ISO8601
               
'DATE_RFC822' => DATE_RFC822,    
               
'DATE_RFC850' => DATE_RFC850,              
               
'DATE_RFC1036' => DATE_RFC1036
               
'DATE_RFC1123' => DATE_RFC1123,
               
'DATE_RFC2822' => DATE_RFC2822
               
'DATE_RFC7231' => DATE_RFC7231,
               
'DATE_RFC3339' => DATE_RFC3339
               
'DATE_RFC3339_EXTENDED' => 
                            
DATE_RFC3339_EXTENDED
               
'DATE_RSS' => DATE_RSS
               
'DATE_W3C' => DATE_W3C ];

foreach(
$datef06a as $k06a => $v06a)
{
    echo 
$k06a '<br>' $v06a '<br>';
    echo 
gmdate($v06a) . '<br><br>';
}

?>