SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    936
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Converting UTC to local time

    I'm importing dates that are in UTC format. Is there an easy way to convert this to EST? Daylight savings is the hitch. It doesn't switch the same date every year, so it seems like figuring the offset based on the date would be tricky.

    Does anyone have any ideas or suggestions?

    E

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    55 Post(s)
    Tagged
    0 Thread(s)
    PHP's DateTime (documentation) class makes working with timezones easy.

    PHP Code:
    $date = new DateTime('2011-11-10 20:17:23', new DateTimeZone('UTC'));
    $date->setTimezone(new DateTimeZone('EST'));

    echo 
    $date->format('Y-m-d H:i:s O'); // 2011-11-10 15:17:23 -0500 
    Salathe
    Software Developer and PHP Manual Author.

  3. #3
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    936
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Salathe,

    Thank you! Brilliant.

    -E


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •