Hi folks.

If you are like me then rendering the correct date took plenty of hours and much head butting of wall to work out.

If you have any tutorials add the please, my head can't take it :)

My scenario:

I have a date stored in db via seblod form. I had trouble displaying the correct time in a position override....

I am in Country A

Server is in Country B

GMT / UTC is in Country C.

Where was my problem?

Solution:

// field with date stored
$dateSchedule = $cck->getValue('scheduled_time'); // 2017-10-30 09:00:00
// get users timezone
$usersTimeZone = new DateTimeZone( JFactory::getUser()->getParam('timezone') );
// create Joomla! date object
$jDate = new JDate($dateSchedule);
// apply users timezone
$jDate->setTimezone($usersTimezone);

// format $jDate I had one line for days and one for time, so...
$jDateDay = $jDate->format('l, d F Y', true, true); // true is important as that renders based on the adjusted timezone.
$jDateTime = $jDate->format('G:i', true, true); // true is important as that renders based on the adjusted timezone.
// - What got me was that even though you have to apply the timezone in setTimezone, you still need the extra step of using it

echo '<div class="why-so-difficult">'.$jDateDay.'</div>';
echo '<div class="easy-when-you-know-how">'.$jDateTime.'</div>';

Jon