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
    another problem, in spanish country date is: dd/mm/yyyy – kraysak Oct 22 '14 at 16:20
  • Do you already have their timezone? If not there are some questions that deal with getting the timezone: http://stackoverflow.com/questions/4746249/get-user-timezone and http://stackoverflow.com/questions/13/determining-a-web-users-time-zone – Gohn67 Oct 22 '14 at 16:24
  • So is!, I have it in a variable... – Gabriel Intriago Oct 22 '14 at 16:26
  • 1
    If you do have timezone, then I think you can use `strftime` with `setLocale`. http://php.net/manual/en/function.strftime.php – Gohn67 Oct 22 '14 at 16:27

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,831
  • 2
  • 28
  • 38
  • 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