1

So I have this component (built with JCB) where I need to display a saved datetime from the db (without seconds, but that's not my focus right now). Because of some limitations, I cannot simply declare use statements at the top of the model.

I'm now at the point that I called the JDate like so:

$date = new Joomla\CMS\Date\Date($item->kickoff);
$datenow = new JDate($item->kickoff);
$dateHtml =  '';
echo '<pre>' . var_export($item->kickoff,true) . '</pre>';
echo '<pre>' . var_export($date,true) . '</pre>';
$item->calculated_name =  $dateHtml;

The export gives me:

'2020-07-30 12:00:00'

Joomla\CMS\Date\Date::__set_state(array(
   'tz' => DateTimeZone::__set_state(array(
       'timezone_type' => 2,
       'timezone' => 'GMT',
   )),
   'date' => '2020-07-30 12:00:00.000000',
   'timezone_type' => 2,
   'timezone' => 'GMT',
))

I should now be able to use the information from the export, but I cannot. I cannot access $date->date or $date->get('date') because it's in set state.

I'm not able to use HtmlHelper because I cannot use it like so:

$dateHtml = new Joomla\CMS\HTML\HTMLHelper($date, Text::_('DATE_FORMAT_FILTER_DATETIME'));

My goal: Access the kickoff date calculated with the offset (Joomla installation timezone)

Any hints?

2

Joomla\CMS\Date\Date doesn't have $date property or get() method. Use $date->format($format) to format the date where $format is the date format.

To format a date using Joomla\CMS\HTML\HTMLHelper, call its underscore method with date as first argument, followed by date and format:

Joomla\CMS\HTML\HTMLHelper::_('date', $item->kickoff, $format);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.