gmmktime(): timestamp of GMT date and time

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 mktime() function of PHP.
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 in output of mktime() and gmmktime()

$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()
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



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-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer