cakePHP ビューでの日付の整形

トラックバック(0) コメント(0)
2009-05-06 03:00:00のような日付のフォーマットを日本語表記に変えたい場合
htmlヘルパーをカスタマイズすると変換が楽になる

$cp cake/libs/view/helpers/html.php app/views/helpers/

としてhtml.phpの複製をしたのち

function dateFormat($date,$format = "Y年m月d日") {
return date($format,strtotime($date));
}
function df($date,$format = "Y年m月d日") {
return $this->dateFormat($date,$format);
}
function dfh($date,$format = "Y年m月d日H時") {
return $this->dateFormat($date,$format);
}
のようにフォーマットを追加して
ビュー内では
$html->dfj($date_str);
※date_strにはタイムスタンプが入っている

参考URL
http://www.jamboree.jp/cms/archives/41
http://cakephp.blog16.jp/index.php/2008/07/01/p27

トラックバック(0)

このブログ記事を参照しているブログ一覧: cakePHP ビューでの日付の整形

このブログ記事に対するトラックバックURL: http://kashioka.net/cgi-bin/mt/mt-tb.cgi/184

コメントする

最近のブログ記事

windows XP でネットワークが表示されない
システムが不安定になっていたマシンがあっ…
MySqlインサート時の文字化け
最近は全部UTF8で作成しちゃっててPH…
Vistaにおけるhostsファイルの書き換え
DNS設定が完了するまでhostsファイ…