Actually I encounter a problem with usage of JDate.

Joomla has a class JDate for managing dates. I tested the following code:

$date = new JDate('2017-07-28 00:00:00');
$timestamp_jdate = $date->toUnix();
$timestamp = strtotime('2017-07-28 00:00:00');

I was expecting that $timestamp_jdate and $timestamp returned the same result but this is the results I obtained: $timestamp_jdate = 1501200000 $timestamp = 1501192800

Did I do something wrong? How can I fix it?

I saw in the API that the JDate constructor can have a second parameter $tz but it is not well documented so maybe I have to set this parameter?

Any help would be grateful :-)


$tz is the timezone. After setting it to the default system timezone the 2 timestamps match! By default, the timezone on Joomla is UTC. My system timezone was 'Europe/Berlin'.

Hope this helps other people.


Let Joomla! take care of stuff for you.

$date = JFactory::getDate('2017-07-28 00:00:00');
$unixDate = $date->toUnix();


$date = new JDate(JHtml::date('2017-07-28 00:00:00', 'Y-m-d H:i:s'));
$unixDate = $date->toUnix();
  • Actually,the timestamp was given by an xml file (outside of Joomla context) so I needed to compare this timestamp to a date which was in my Joomla database.
    – quokka-web
    Aug 10 '17 at 14:45

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.