AFAIK there is no automatic way to do this kind of time zone adjustment in EE.
EE stores times relative to the server's location timezone, or relative a different timezone if you specify it in the CP. Dynamically modifying the server's default timezone on the fly is not a sensible option, so whatever you do will require you to modify the times shown to the user relative to the stored 'EE server time' for the event.
In light of this you have two options: dynamically modifying the displayed value in php or in javascript.
- In php you can do this using the
DateTimeZone
object - once you know what timezone you want to use, you'll need code something like this to set the value
$localTimezone = new DateTimeZone($time_zone_code);
$displayDateTime = new DateTime('NOW', $localTimezone);
- In Javascript you can do this using the javascript
Date()
class getTimezoneOffset
method to get the difference in minutes between UTC time and the local time for the browser running the script - something like:
var localTime = new Date();
var localTimeZoneDifference = localTime.getTimezoneOffset();
Depending on what option you choose, you could then store either the $time_zone_code
(e.g. 'GMT') value or localTimeZoneDifference
value (e.g. 120
) in a field linked to your user.
Whichever option you choose you'll still need to do more work to actually deploy the approach to give you the time outputs you want. Javascript might be a better option as the browser already knows about time zone differences through the Date()
class. To use php you'd need to use an add-on to get you the time zone information. If you ask the authors there might be an EE2 version of the IP Geo Locator plugin available, or if not you maybe can rig up something that uses the EE IP to Nation plugin.
HTH