The gmmktime() function in PHP returns a Unix timestamp for a date based on GMT (Greenwich Mean Time). It works similarly to the mktime() function but differs in that gmmktime() always uses GMT, unaffected by the local timezone.
gmmktime(hour, minute, second, month, day, year, is_dst);
hour: Specifies the hour.
minute: Specifies the minute.
second: Specifies the second.
month: Specifies the month.
day: Specifies the day.
year: Specifies the year.
is_dst: Indicates whether daylight saving time is in effect. Since gmmktime() works with GMT, this parameter has no effect on the result.
This function returns an integer Unix timestamp that represents the number of seconds since January 1, 1970, 00:00:00 GMT.
Here’s a basic example:
<?php
$time = gmmktime(0, 0, 0, 9, 10, 2017);
print($time . "\n");
?>
1505001600
This example shows how to combine gmmktime() with the date() function:
<?php
echo "Nov 10, 2017 was on a " . date("l", gmmktime(0, 0, 0, 11, 10, 2017));
?>
Nov 10, 2017 was on a Friday
The gmmktime() function is very useful when dealing with time calculations that should remain independent of time zones. It is often used for internationalized applications, log recording, or any scenario requiring GMT-based time comparisons. Understanding how to use gmmktime() helps developers manage and convert time data more effectively.