How to display time for different timezones?

Discussion in 'PHP' started by Professional Dude, Aug 3, 2009.

  1. #1
    Hi,

    I am trying to display time in php for different time zones, such as +1, +6 or any other time zone,
    what code can I use to display current time for specific zones?

    Any help would be appreciated! ;)

    Thanks
     
    Professional Dude, Aug 3, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Take a look at php.net/manual/en/class.datetimezone.php as a starting point for what you want. (You'll need php 5.2+)

    
    <?php
    // Create two timezone objects, one for Taipei (Taiwan) and one for
    // Tokyo (Japan)
    $dateTimeZoneTaipei = new DateTimeZone("Asia/Taipei");
    $dateTimeZoneJapan = new DateTimeZone("Asia/Tokyo");
    
    // Create two DateTime objects that will contain the same Unix timestamp, but
    // have different timezones attached to them.
    $dateTimeTaipei = new DateTime("now", $dateTimeZoneTaipei);
    $dateTimeJapan = new DateTime("now", $dateTimeZoneJapan);
    
    PHP:
     
    premiumscripts, Aug 3, 2009 IP
    Professional Dude likes this.
  3. gyanprakash

    gyanprakash Peon

    Messages:
    5
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    or you will use +GMT link time zone according to different country
     
    gyanprakash, Aug 3, 2009 IP
    Professional Dude likes this.
  4. Professional Dude

    Professional Dude Prominent Member

    Messages:
    6,261
    Likes Received:
    430
    Best Answers:
    0
    Trophy Points:
    330
    #4
    Thanks for your responses, but can anyone give me example code to display time for +1 zone?
     
    Professional Dude, Aug 3, 2009 IP