gpt4 book ai didi

php - 如何获得 Twig 的天数差异

转载 作者:可可西里 更新时间:2023-11-01 12:26:03 30 4
gpt4 key购买 nike

  • 如何获取与当天相差的天数。

  • tweetedAt:“2015-02-22 09:56:42”。

Twig

{% for key,value in data.about %}
{% set tweets_date=(value.tweetedAt|date).date("now").format('%a') %}
{% endfor %}

我也试过

{% set dd='now'|date('d-m-Y') %}
{% set tweets_date=(value.tweetedAt|date).dd.format('%a') %}

最后我试过了,但它给出了错误:

A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "punctuation" of value "{"

{% set difference = {{ date("m/d/Y") }}.diff(date(value.tweetedAt)) %}
{% set leftDays = difference.days %}

错误:

<span class="small light_grey">{{tweets_date}}</span>

Impossible to invoke a method ("date") on a string variable ("June 6, 2015 01:06") in AcmeBundle
  • 如何从 tweet_date 中获取几天前的差异。

更新了我的项目,通过 composer 安装 twig/extensions

user@intermsh-OptiPlex-380:~$ composer require twig/extensions
Warning: This development build of composer is over 30 days old. It is recommended to update it by running "/usr/local/bin/composer self-update" to get the latest version.
Using version ~1.2 for twig/extensions
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing twig/twig (v1.18.2)
Downloading: 100%

- Installing twig/extensions (v1.2.0)
Downloading: 100%
Downloading: 100%

twig/extensions suggests installing symfony/translation (Allow the time_diff output to be translated)
Writing lock file
Generating autoload files

最佳答案

我试过这段代码,它有效。

{% set difference = date(value.tweetedAt|date('Y/m/d')).diff(date('now'|date('Y/m/d'))) %}
{% set leftDays = difference.days %}

关于php - 如何获得 Twig 的天数差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30839618/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com