沃梦达 / 编程问答 / php问题 / 正文

如何获得树枝的天差

How to get days difference in twig(如何获得树枝的天差)

本文介绍了如何获得树枝的天差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 如何获取与当天的天数差异.

  • how to get days diffrence from current day.

tweetedAt:2015-02-22 09:56:42".

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') %}

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

Finally I tried but its giving error:

哈希键必须是带引号的字符串、数字、名称或括在括号中的表达式(值{"的意外标记标点符号"

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 在几天前的形式中获取差异.
    • how to get diffrence from tweet_date in days ago form.
    • 更新了我通过 composer 安装 twig/extensions 的项目

      Updated my project installing twig/extensions via composer

      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
      

      推荐答案

      我试过这段代码,它可以工作.

      I tried this code and it works.

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

      这篇关于如何获得树枝的天差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何获得树枝的天差

基础教程推荐