I have a method that is called whenever I want to output a readable date(all of my dates and times are stored as unix timestamps). In the method, I want it to convert the time based on the user's timezone.
Code: Select all
public function formatDate($timestamp, $time = false) {
$dateformat = Model_CurrentUser::getInstance()->dateFormat;
$timeformat = Model_CurrentUser::getInstance()->timeFormat;
$timezone = Model_CurrentUser::getInstance()->timezone;
//$result = '';
$date = new DateTime(date('r', $timestamp), new DateTimeZone($timezone));
// .............
// Then at the end of the method
$result = $date->format($dateformat);
return $result;