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';This current example appears first; the detailed examples below are retained and modernized for comparison and additional use cases.
gmmktime (hour, minute, second, month, day, year)
Output is timestamp$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 heremktime(): 1482170815
gmmktime() : 1482190615
Difference : 19800
| Function | Description |
|---|---|
| strtotime() | Text string of data to timestamp |
| gettimestamp() | Getting Timestamp from date object |
$utc_time = gmmktime(12, 30, 0, 7, 10, 2023);
echo date("Y-m-d H:i:s", $utc_time); // Output: UTC date and time
$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
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.