如何在for循环中将n天添加到树枝日期格式? [英] How to add n-days to twig date format within a for-loop?

查看:33
本文介绍了如何在for循环中将n天添加到树枝日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 twig 并且得到了日期和格式.我有一个开始日期(比方说今天),我想每天都打印到表格单元格中.

I'm working with twig and got the date and format working. I have a start date (let's say todays day) and I'd like to print every day into a table cell.

我在 var 数据中有我的日期字段,我可以用它添加 1 天.它正在工作.

I have my date field in the var datum and I'm able to add 1 day with this. it's working.

{% set datum = date(current_user.cwmon)|date_modify("+1 day")|date('D d.m.y') %}

当我将其放入 for 循环时,我得到的不是我想要的答案.

when I put this into a for loop, I get not the answer I'd like to.

代码本身:

{% for j in 0..6 %}
    {% set datum = date(current_user.cwmon)|date_modify("+1 day")|date('D d.m.y') %}
    // other code
    {{ j }}: {{ datum }}
    // other code
{% endfor %}

有没有办法使用我的 var j 而不是 +1 天?无论我尝试什么,都会出错.

is there a way to use my var j instead of +1 day? Whatever I try I get an error.

我想要的结果:

0: Mon 15.01.19
1: Tue 16.01.19
...
6: Sun 20.01.19

非常感谢您.

推荐答案

显然答案很简单.

    {% for j in 0..6 %}
         {% set datum = YOUR_DATE|date_modify("+" ~ j ~ " day")|date('D d.m.y') %}
    {% endfor %}

有了这个, datum 具有正确的值并将 j 添加到自身.

with this, datum has the correct value and adds j to itself.

这篇关于如何在for循环中将n天添加到树枝日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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