简体   繁体   English

使用TWIG / Symfony 2将整数转换为日字符串

[英]Integer to day string with TWIG / Symfony 2

I'm looking for a solution to write a day as string from an Integer. 我正在寻找一种解决方案,以将整数作为整数来写一天。

I found this to have the current day as a string. 我发现这是当前日期作为字符串。

{{ 'now' | localizeddate("none", "none", null, null, "EEEE") | capitalize }}

Result => Monday 结果=> Monday

But I would like to replace 'now' by an integer. 但我想用一个整数代替'now'

1 for Monday 2 for Tuesday 3 for W... 1代表星期一2代表星期三3 W ...

In your Controller PHP : 在您的Controller PHP中:

$day_number = date('N', strtotime('Monday'));

In your TWIG template : 在您的TWIG模板中:

{{ day_number | localizeddate("none", "none", null, null, "EEEE") | capitalize }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM