如何避免TYPO3中的日期时间问题? [英] How can I avoid datetime problems in TYPO3?

查看:51
本文介绍了如何避免TYPO3中的日期时间问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个扩展名,它使用日期时间查看某些特定事件(事件日期和事件时间),但是如果尝试从数据库到前端获取正确的日期时间,我总是会遇到麻烦.

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.

我可以通过TYPO3后端为每个事件设置日期时间:

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>

然后输出不是"10.04.2016-08:00:00",它是"10.04.2016-10:00:00".

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?

推荐答案

在TYPO3中,日期转换存在一些不一致之处,它在TCE和Extbase中的行为有所不同.Extbase认为所有日期都存储在UTC中的数据库中,因此在数据映射过程中会将您的日期从UTC转换为理论上的本地时间(不应该执行IMHO或应通过Install Tool进行配置的IMHO),这是肮脏但可行的技巧正在欺骗TYPO3,只需在 Install Tool > 所有配置中找到 [SYS] [phpTimeZone] 设置并将其值设置为 UTC .

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.

这样,Extbase会认为您位于UTC区域内,无需更改php.ini中的任何内容.

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

这篇关于如何避免TYPO3中的日期时间问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆