Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在fatfree模板中设置日期格式?_Php_Html_Fat Free Framework - Fatal编程技术网

Php 如何在fatfree模板中设置日期格式?

Php 如何在fatfree模板中设置日期格式?,php,html,fat-free-framework,Php,Html,Fat Free Framework,是否有可能以及如何使用模板自身的功能在无脂肪框架内格式化日期 <repeat group="{{ @rows }}" value="{{ @row }}"> <tr> <td>{{ @row.idbox }}</td> <td>{{ @row.code }}</td> <td>{{ @row.createon }}</td>//date

是否有可能以及如何使用模板自身的功能在无脂肪框架内格式化日期

<repeat group="{{ @rows }}" value="{{ @row }}">
      <tr>
         <td>{{ @row.idbox }}</td>
         <td>{{ @row.code }}</td>
         <td>{{ @row.createon }}</td>//date to format
         <td>{{ @row.senton }}</td>
         <td>{{ @row.price }}</td>
      </tr>
</repeat>

该框架不提供用于日期格式设置的专用过滤器

格式过滤器 您可以使用语法,但语法有点特殊,因为它主要用于本地化字符串:

使用本地化字符串: index.php

$f3->PREFIX='dict'; $f3->LOCALES'dict/'; $tpl=模板::实例; echo$tpl->render'template.html'; dict/en.ini

template.html

自定义过滤器 幸运的是,该框架使我们有可能创建:

index.php

$tpl=模板::实例; $tpl->filter'date','MyFilters::date'; echo$tpl->render'template.html'; myfilters.php

类MyFilters{ 静态函数日期$time,$format='Y-m-d'{ 如果!是数值$time $time=strottime$time;//将字符串日期转换为unix时间戳 返回日期$格式$时间; } } template.html


使用标准的php日期函数。前面的答案是获得相同结果的非常复杂的方法:

{{  date('d M Y',strtotime(@row.createon))  }}

您需要使用strotime的原因是因为F3的::template视图将变量呈现为字符串,即使它们是数据库中的timestamp/datetime。

您已经尝试了什么(如果有的话)?我无法理解..根据尝试尝试尝试尝试{{{{0,date}',@row.createon | format}。。此日期2017-03-10 12:26:28的格式类似于1970年1月1日出错的原因是日期格式化程序需要unix时间戳。尝试在以下时间之前转换:{{0,date},strtotime@row.createon|格式}}。
<!-- with a UNIX timestamp -->
<td>{{ dict.order_date, @row.createon | format }}</td>

<!-- with a SQL date field -->
<td>{{ dict.order_date, strtotime(@row.createon) | format }}</td>
<!-- with a UNIX timestamp -->
<td>{{ '{0, date}', @row.createon | format }}</td>

<!-- with a SQL date field -->
<td>{{ '{0, date}', strtotime(@row.createon) | format }}</td>
<!-- default Y-m-d format -->
<td>{{ @row.createon | date }}</td>

<!-- custom format Y/m/d -->
<td>{{ @row.createon, 'Y/m/d' | date }}</td>
{{  date('d M Y',strtotime(@row.createon))  }}