0

I need to show the user the date of an event, depending on the time zone you are. Example ... If they are at 2014-10-22 11:05:00 (time of event) ...

madrid show 2014-10-22 18:05:00

or

Tokio show 2014-10-23 01:05:00

can you help me?

Thanks

1 Answers1

0

DateTime class is your friend here.

<?php
$date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru')); #What you have
echo $date->format('Y-m-d H:i:sP') . "\n";

$date->setTimezone(new DateTimeZone('Pacific/Chatham')); # What you want to spit out.
echo $date->format('Y-m-d H:i:sP') . "\n";
?>

Source

Community
  • 1
  • 1
David
  • 3,722
  • 2
  • 21
  • 34
  • Thank you, helped me a lot! :) – Gabriel Intriago Oct 22 '14 at 16:49
  • 1
    `DateTime` is your answer to time/date-related issues 99.999% of the time. The most portable way, however, is to convert your time/date string to epoch time and add or subtract the number of seconds required for the shift. However, with the method above, you can present the user with a dropdown of [supported timezones](http://php.net/manual/en/timezones.php) and just pass it directly to `setTimezone()`. – David Oct 22 '14 at 16:50