如何使用Twig日期以中文显示星期几? [英] How to use Twig date to show week day in Chinese text?

查看:79
本文介绍了如何使用Twig日期以中文显示星期几?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示日期格式,例如: 10月09日,周三(星期三表示10/9)。

和我的数据是UNIX时间,例如[message.time]: 1380813820000


,所以这是我在树枝上所做的:

{{(message.time / 1000)| date( m月d日,周w)}}

但是它告诉我: 10月09日,周3 ,因为日期 w是数字,而不是中文文本。


所以我可以用Twig做任何事情来转换文本格式吗?

I want to show the date format like: 10月09日, 周三 (which means 10/9, Wed.)
and my data is UNIX time like [message.time]: 1380813820000

so this is what I do in twig:
{{ (message.time/1000)|date("m月d日, 周w") }}
But it show me: 10月09日,周3, Because date "w" are numbers, not Chinese text.

so can I do anything by Twig to converse the text format?

谢谢

推荐答案

我找到了一个快速过滤器 replace ,这是代码段:

I found a quick filter replace , here is the code snippet:

<div class="date"><span>{{ (create_time/1000)|date("m月d日,周D")|replace({'Mon':'一','Tue':'二','Wed':'三','Thu':'四','Fri':'五','Sat':'六','Sun':'日'}) }}</span></div>

这篇关于如何使用Twig日期以中文显示星期几?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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