LoginSignup
3
4

More than 5 years have passed since last update.

Smarty 日付データを整形して出力

Last updated at Posted at 2016-01-19

基本ですがすぐ忘れてしまうのでメモ。
Smartyで日付を整形して出力する方法。

{$data|escape}
/* 表示結果 */
2016-01-01 00:00:00

これを「2016年01月01日」と表示したい場合、「date_format」を使います。

{$data|date_format:"%Y年%m月%d日"}
/* 表示結果 */
2016年01月01日

追記

Smartyのdate_formatってphpのdate関数のフォーマットに則ってると思ってたんですが、どうやら違うみたいで、ちょびっとハマった...。

$date = date('Y-m-d H:i:s');
/* 表示結果 */
2016-01-01 00:00:00

時間を上記通りに出力する場合、H:i:sでは上手く表示されない。

{$data|date_format:'%Y-%m-%d %H:%M:%S'}
/* 表示結果 */
2016-01-01 00:00:00

上記の通り、%H:%M:%Sでした...。
勝手な思い込み、危険。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4