php – 如何在树枝上获得天数差异

前端之家收集整理的这篇文章主要介绍了php – 如何在树枝上获得天数差异前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
>如何从当天获得天差异. @H_301_1@> tweetedAt:“2015-02-22 09:56:42”.

枝条

{% 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获取diffrence形式.

通过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相关文章