How to deduce DateTime correctly with TYPO3 extrusion liquid

I have two DateTime objects stored in a database:

  • 2014-11-03 09:00:00
  • 2014-10-21 13:45:00

When I try to output them using ViewHelper format.date

<f:format.date format="H:i">{termin.datumBeginn}</f:format.date>

      

I get the following results:

  • 10:00
  • 15:45

So, I got a one hour shift and a two hour shift that I can't write a workaround for. How do I properly configure timezones for clean output?

+3


source to share


4 answers


Although this is very old, I want to emphasize that until recently this was a bug in Extbase and we fixed it in TYPO3 7.6 and 8. Dates are now correctly read as UTC as they are stored in the database and converted to your timezone. server.



+5


source


Make sure all dates in your database are in the same time zone, because this information is not stored there. When you get some objects from external API calls, they will have a timezone in the date string, and this will usually be UTC. From your internal calls, all \ DateTime objects will use your server's default timezone by default. So set your timezone before storing it in the database:

$receivedDate = new \DateTime($date);
$reveivedDate->setTimezone(new \DateTimeZone(date_default_timezone_get()));

      



Setting the default timezone for the server is handy because no more changes are required .. but it's better to store it in 'UTC' I think. In this case, you will need to set it back to your server / user timezone before showing it. This can be done in the ViewHelper (not the default from Typo3.Fluid, but you can easily extend it in your package - clone and set the timezone again). Perhaps it is now possible to use doctrine extensions in a stream and save the timezone with the date in the database. I tried it a year ago and was unable to do it.

+3


source


To solve this problem, you need to set $ TYPO3_CONF_VARS ['SYS'] ['phpTimeZone'] as "UTC" and $ TYPO3_CONF_VARS ['SYS'] ['serverTimeZone'] as "0" (perhaps only the first setting will be sufficient ). You can do this through the back-end of typo3 using the Install tool. If you have a domain model, you can use a workaround:

/**
 * Returns the startDate
 *
 * @return \DateTime|NULL $startDate
 */
public function getStartDate() {
    $date = $this->startDate;
    if($date) {
        $date->setTimezone(new \DateTimeZone('UTC'));
    }
    return $date;
}

      

+1


source


Please make sure you have set Timezone for PHP in your php.ini file

Example: date.timezone = "Asia/Phnom_Penh"

      

For more details on PHP Timezone see this link: http://php.net/manual/en/timezones.america.php

0


source







All Articles