Easy Way to Convert UTC to Current Timezone in PHP


$utc_time = "2009-01-12 21:28:21"; // As pulled from the database
date_default_timezone_set("America/New_York"); // Set to Eastern time (automatically handles daylight savings time)

// Here's the secret: add a Z (for zulu) to the end of your UTC date/time string
$utc_time .= "Z";

// Now convert to the current timezone
$cur_date = strftime("%G-%m-%d %H:%M:%S", strtotime($utc_time)); // Format as YYYY-MM-DD HH:MM:SS


The result: 2009-01-12 16:28:21

How do you handle this? Let me know in the comments.

Share