LoginSignup
25
23

More than 5 years have passed since last update.

strftimeで和暦表示

Last updated at Posted at 2013-05-30

PHPで和暦表示をしたい場合、オリジナルな関数を作成しなくても、
strftimeで以下のように変換指定子を指定するといけるかも。
(Cライブラリに依存、windowsでは動作しなかった)

例えば、
平成x年x月x日 x曜日と表示したいのなら、以下のようにする。

<?php
   setlocale(LC_TIME, "ja_JP.utf8", "Japanese_Japan.932");
   print strftime('%EC%Ey年%B%#d日 %A');
?>

結果

平成25年5月30日 木曜日




'%Ec'を指定すると、ロケールの日付・時間を表示してくれる。

<?php
   setlocale(LC_TIME, "ja_JP.utf8", "Japanese_Japan.932");
   print strftime('%Ec');
?>

結果

平成25年05月30日 18時04分52秒





参考:
» Open Group による strftime() の定義

25
23
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
25
23