gigi
gigi

Reputation: 181

Show multiple datetime with different timezone

is it possible in php to show in the same page different date-time that belongs to different timezones?

For exemple if I want to show date and time of 2 different location in the world.

not sure if its right but i tryed this:

    <div>
    <?php
    date_default_timezone_set("Europe/Rome");
    echo " Italy time: " . date("h:i:sa");
    echo " day " . date("d/m/Y") . "<br>";
    ?>
    </div>
    <div>
    <?php
    date_default_timezone_set("Asia/Vientiane");
    echo "Vietnam time " . date("h:i:sa");
    echo " day " . date("d/m/Y") . "<br>";
    ?>
    </div>

Upvotes: 0

Views: 124

Answers (2)

Imran
Imran

Reputation: 3072

Why not. you can use DateTime class

   $datetime = new DateTime($dbTimestamp, $timezone);
     $datetime->format('Y-m-d H:i:s');
    $Newyork_time = $datetime->setTimezone(new DateTimeZone('America/New_York'));
    $Dhaka_time = $datetime->setTimezone(new DateTimeZone('Asia/Dhaka'));

Upvotes: 1

Sven R.
Sven R.

Reputation: 1057

You can instantiate DateTime with a timezone of your wish:

$dateAfrica = newDateTime('now', new DateTimeZone('AFRICA'));
$dateAmerica = newDateTime('now', new DateTimeZone('AMERICA'));

To output the dates:

echo $dateAfrica->format('r');
echo $dateAmerica->format('r');

Upvotes: 0

Related Questions