How can the mktime() function be used to manipulate timestamps in PHP, specifically for adjusting time zones?
To adjust timestamps for different time zones in PHP, you can use the mktime() function along with functions like date_default_timezone_set() to set the desired time zone. By manipulating the parameters of mktime() and setting the time zone accordingly, you can easily convert timestamps to different time zones.
// Set the default time zone to UTC
date_default_timezone_set('UTC');
// Create a timestamp for a specific date and time
$timestamp = mktime(12, 0, 0, 1, 1, 2022);
// Set the desired time zone
date_default_timezone_set('America/New_York');
// Convert the timestamp to the new time zone
$new_timestamp = date('Y-m-d H:i:s', $timestamp);
echo $new_timestamp;