【问题标题】:Calculate age in typoscript在打字稿中计算年龄
【发布时间】:2017-01-26 20:52:59
【问题描述】:

我正在尝试根据时间戳计算年龄,例如。打字稿中的 761353200。时间戳 761353200 是 1994 年 2 月 16 日。

我正在将数据从 Fluid-Template 发送到 Typoscript:

<f:cObject typoscriptObjectPath="lib.userAge">
    <f:format.date format="U">{user.dateOfBirth}</f:format.date>
</f:cObject>

在这种情况下,{user.dateOfBirth} 等于 761353200。

Typoscript 中的计算如下所示:

lib.userAge = TEXT
lib.userAge.current = 1
lib.userAge.age = 1

问题:返回值是23,但应该是22。

我用另一个时间戳 (556408800) 尝试了它,它返回 29,这是应该的。这让我非常困惑。

有人知道为什么计算会这样吗?

【问题讨论】:

    标签: typoscript fluid typo3-7.6.x


    【解决方案1】:

    我认为这种转换太不精确了。为什么不使用不使用打字稿的流体视图助手?所以代码更好维护。 我找到了这个 ViewHelper。您可以将其复制并集成到您的扩展/模板中吗? https://searchcode.com/codesearch/view/39628010/

    【讨论】:

    • 我怎么没想到... ._。谢谢。实际上,您链接的 ViewHelper 太多了。我的现在看起来像这样就足够了:public function render($timestamp) { $inputDate = date('Y-m-d H:i:s', $timestamp); $returnDate = intval(date('Y', time() - strtotime($inputDate))) - 1970; return $returnDate; }
    猜你喜欢
    • 1970-01-01
    • 2014-11-16
    • 2017-05-26
    • 2017-08-08
    • 2012-03-26
    • 1970-01-01
    • 2020-12-28
    • 2016-03-20
    • 2011-04-16
    相关资源
    最近更新 更多