How can I avoid datetime problems in TYPO3?

孤街醉人 提交于 2019-12-24 00:25:44

问题


I have created a little extension which uses datetimes to view some specific events (event date and event time), but I always run into trouble if I try to get the correct datetime from database to frontend.

I can set the datetime for each event via TYPO3 backend:

But if I try to get this value on frontend like:

<f:format.date format="d.m.Y - H:i:s">{event.appointment}</f:format.date>

Then the output is not "10.04.2016 - 08:00:00" it is "10.04.2016 - 10:00:00".

How can I avoid this behaviour? I have set the timezone via install tool too:

[SYS][phpTimeZone] = Europe/Berlin

but I get always the wrong datetime. If I try something like this:

DebugUtility::debug(new \DateTime());

then I get the correct output:

{"date":"2016-04-09 20:23:38.000000","timezone_type":3,"timezone":"Europe\/Berlin"}

If I take a look at the database I can see that the correct datetime is stored:

So I don't know why I got the wrong datetime, any suggestions?


回答1:


There is some inconsistency with date converting within TYPO3 it behaves different in TCE and in Extbase. Extbase considers that all dates are stored in DB in UTC therefore at data mapping process converts your date from UTC to theoretically local time (IMHO that shouldn't be done or should be configurable via Install Tool), the dirty but working trick is fooling TYPO3, just in the Install Tool > All configurations find the [SYS][phpTimeZone] setting and set its value to UTC.

That way Extbase will think that you're within UTC zone and you won't need to change anything in the php.ini.



来源:https://stackoverflow.com/questions/36521073/how-can-i-avoid-datetime-problems-in-typo3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!