If this is not done via a user profile setting, it is probably easier and simpler to use a javascript time library eg. moment.js (http://momentjs.com/) to solve this problem (send all date/times in UTC and then convert them on the client end).
Javascript eg. (I am sure this can be achieved without creating two moment objects (fix that at your leisure).
function utcToLocalTime(utcTimeString){
var theTime = moment.utc(utcTimeString).toDate(); // moment date object in local time
var localTime = moment(theTime).format('YYYY-MM-DD HH:mm'); //format the moment time object to string
return localTime;
}
php example for server side resolution (only use one of these solutions, both together will produce an incorrect time on the client end)
/**
* @param $dateTimeUTC
* @param string $timeZone
* @param string $dateFormat
* @return string
*
* epoch to datetime (utc/gmt)::
* gmdate('Y-m-d H:i:s', $epoch);
*/
function dateToTimezone($timeZone = 'UTC', $dateTimeUTC = null, $dateFormat = 'Y-m-d H:i:s'){
$dateTimeUTC = $dateTimeUTC ? $dateTimeUTC : date("Y-m-d H:i:s");
$date = new DateTime($dateTimeUTC, new DateTimeZone('UTC'));
$date->setTimeZone(new DateTimeZone($timeZone));
return $date->format($dateFormat);
}