Smarty 模板 date_format 给出了不可预测的结果

Smarty Template date_format gives unpredictable results

我将时间戳传递给 Smarty 模板,使用 date_format 会产生不可预测的结果。这是最优雅地演示问题的示例模板:

{"1456602208"}
{"1456602208"|date_format}
{"1432808316"}
{"1432808316"|date_format}

此模板的输出:

1456602208
Oct 19, 2208
1432808316
May 28, 2015

第二个日期的格式正确。但是,第一个应该是

Feb 27, 2016

这是为什么?

避免这种情况的最佳方法是将时间戳转换为 int。现在是数字 string.

Smarty 在 2.6.10 中做了一些更改,使用所有数字输入值作为时间戳,但以前并非总是如此。

正如我所看到的,第一个时间戳以 2208 结尾,而且该时间戳返回的年份是 2208,所以我认为聪明人认为它不是时间戳,而是某种格式的日期。

查看更多here (smarty doc)