Question

Do you know of any way to check the current time in Joomla considering the selected time zone in global configuration? I have been looking in administrator settings but did not see any single word about the current time.

Was it helpful?

Solution

You can use the following code:

$date = new DateTime();
$config = JFactory::getConfig();
$date->setTimezone(new DateTimeZone($config->get('offset')));

This does two things. The first line creates a DateTimeobject based on the current server time and timezone. The following two lines get Joomla's global configuration and change the timezone of out date object to that timezone.

You can then format the date to whatever format you like by calling $date->format('Y-m-d H:i:s');. You can replace the format specifier by whatever you need, a reference of possible formatting options can be found here: http://www.php.net/manual/de/function.date.php

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top