If this is not done by setting a user profile, it may be easier and easier to use a javascript time library, for example. moment.js ( http://momentjs.com/ ) to solve this problem (send all dates / times to UTC and then convert them to the end of the client).
Javascript for example. (I am sure that this can be achieved without creating two objects of the moment (fix this at your leisure).
function utcToLocalTime(utcTimeString){ var theTime = moment.utc(utcTimeString).toDate();
An example php for server-side resolution (use only one of these solutions, both together will create the wrong time on the client side)
function dateToTimezone($timeZone = 'UTC', $dateTimeUTC = null, $dateFormat = 'Ymd H:i:s'){ $dateTimeUTC = $dateTimeUTC ? $dateTimeUTC : date("Ymd H:i:s"); $date = new DateTime($dateTimeUTC, new DateTimeZone('UTC')); $date->setTimeZone(new DateTimeZone($timeZone)); return $date->format($dateFormat); }
Robin
source share