gmmktime(): timestamp of GMT date and time

Create a UTC timestamp with gmmktime()

Use gmmktime() when the supplied date and time components represent UTC. For new object-oriented date calculations, DateTimeImmutable with an explicit UTC timezone is usually easier to read.

$timestamp = gmmktime(12, 30, 0, 9, 14, 2026);
echo gmdate('Y-m-d H:i:s', $timestamp) . ' UTC';
We can generate number of seconds measured since the Unix Epoch (January 1 1970 00:00:00 GMT) for any given Greenwich Mean Time GMT date and time by using gmmktime function of PHP. Here is the general syntax of gmmktime().
gmmktime($hour, $minute, $second, $month, $day, $year)
Output is timestamp
This function is same as mktime() except the passed parameters represents a GMT date.

Difference between local and UTC components

The difference depends on the configured timezone. This example sets the timezone explicitly so the result is reproducible.

date_default_timezone_set('Asia/Kolkata');
$d1=mktime(23,36,55,12,19,2016);
$d2=gmmktime(23,36,55,12,19,2016);
$d3=$d2-$d1;
echo " mktime(): {$d1} <br> gmmktime(): {$d2} <br> Difference: {$d3}";
Output is here
mktime(): 1482170815 
gmmktime() : 1482190615 
Difference : 19800

Other ways to get Unix Timestamp

Function Description
strtotime()Text string of data to timestamp
gettimestamp()Getting Timestamp from date object

Example: Generating UTC Timestamp

$utc_time = gmmktime(12, 30, 0, 7, 10, 2023);
echo date("Y-m-d H:i:s", $utc_time);  // Output: UTC date and time

Example: Comparing gmmktime() and mktime()

$local_time = mktime(12, 30, 0, 7, 10, 2023);
$utc_time = gmmktime(12, 30, 0, 7, 10, 2023);
echo date("Y-m-d H:i:s", $local_time);  // Local time
echo '
'
; echo date("Y-m-d H:i:s", $utc_time); // UTC time
Output
2023-07-10 12:30:00
2023-07-10 14:30:00

PHP Date Functions GMT/UTC date/time Date formats for Date()


Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer