简体   繁体   English

Symfony2 Twig日期(“H”)“军事时间”

[英]Symfony2 Twig date(“H”) “Military Time”

I have an application in Symfony where when a user posts a comment, the comment's creation time is stored. 我在Symfony中有一个应用程序,当用户发表评论时,会存储评论的创建时间。 Then, it is converted to the correct format with twig, like so: 然后,使用twig将其转换为正确的格式,如下所示:

{{ comment.created|date('m-d-Y H:i:s a') }}

The only problem is, if the user submitted the comment at 4 PM, it comes up as 16 PM 唯一的问题是,如果用户在下午4点提交评论,则会在下午16点提交

I'd like it to just show 4 PM 我希望它只显示下午4点

Thanks in advance for all the help! 在此先感谢您的帮助!

Use h instead of H h代替H

{{ comment.created|date('m-d-Y h:i:s a') }}

From: https://php.net/manual/en/function.date.php 来自: https//php.net/manual/en/function.date.php

h 12-hour format of an hour with leading zeros h带有前导零的12小时格式的小时

H 24-hour format of an hour with leading zeros H带有前导零的24小时格式

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

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