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

Posted

in

, ,

by

Tags:

Comments

2 responses to “Easy Way to Convert UTC to Current Timezone in PHP”

  1. Mark Avatar

    I just let my coworkers figure it out 😛

  2. Jeremy Avatar
    Jeremy

    What’s new? 😉

Leave a Reply

Your email address will not be published. Required fields are marked *