Creating Timestamps from GMT Date and Time Values

0
5

mktime() assumes that the arguments you pass are in your computer’s time zone, it converts the supplied time to UTC so that it can be returned as a timestamp. However, sometimes it is useful to be able to store a date and time that is already in the GMT time zone.
For example, many HTTP headers and other TCP/IP protocols work with dates and times that are always in GMT.

To create a timestamp from a GMT date and time, use gmmktime(). This works exactly the same way as mktime() , except that it expects its arguments to be in GMT.
For example, let us say the computer running the PHP script is in the Indianapolis time zone, which is 5 hours behind GMT, and that it is running the following code:

$localTime = mktime( 14, 32, 12, 1, 6, 1972 );
$gmTime = gmmktime( 14, 32, 12, 1, 6, 1972 );

After this code has run, $localTime holds the timestamp representing Jan 6, 1972 at 7:32:12 pm GMT/ UTC (which is 2:32 pm on the same day Indianapolis time). Meanwhile, $gmtime holds the timestamp for 2:32:12 pm GMT/UTC.
mktime() and other date – related functions use the time zone set by the date.timezone directive in the php.ini file. However you can, if desired, change the time zone used by the PHP script with the date_default_timezone_set() function.