Smartyのdate_formatの年月日表示と文字化け

まず文字化けから。

{$smarty.now|date_format:"%Y年%m月%d日"}

とやると、

2008年10月%d日

となることがあります。詳しく調べていないんですが、文字コードなど環境によって起こるみたいです。
これを回避する方法です。

{$smarty.now|date_format:"%Y年%m月%d日"}

参考→http://code.xenophy.com/?p=184


次に年月日の表示。

Smartyのdate_formatだと、「2008年9月1日」という表示ができないんです。「%Y年%m月%d日」だと「2008年09月01日」になってしまいます。「%e」を使えば日の頭のゼロは取り除けるのですが、月はどうがんばっても頭にゼロを取り除くことができません。

解決策はこんな感じでプラグインを自作してしまうこと。

function smarty_modifier_org_date_format($string, $format){
if (!is_numeric($string)){
$string = strtotime($string);
}
return date($format, $string);
}

参考→http://www.phppro.jp/qa/45