Wordpressメモ
Posts tagged 日時
mktime関数
8月 4th
dateはタイムスタンプから普段見慣れた日付に変更してくれる関数なら、mktimeは普段見慣れた日付をタイムスタンプに変更するようなもの。その中で色々と計算する事によって、数日前や数年後などを計算する事ができる。
例
<?php
$y = date(“y”);
$m = date(“m”);
$d = date(“d”);
$after_10day=mktime(0,0,0,$m,$d+10,$y);
echo date(“Y年m月d日”,$after_10day).”<br />\n”;
$getumatubi=mktime(0,0,0,$m,0,$y);
echo date(“Y年m月d日”,$getumatubi).”(←先月の最終日)\n”;
?>
結果
2008年08月14日
2008年07月31日(←先月の最終日)
※$getumatubi=mktime(0,0,0,$m,0,$y);の赤文字部分を0指定する事で、先月末の日付を取得できる。
date関数(日付を表示させる)
8月 4th
date(日付フォーマット,[タイムスタンプ]);
例
<?php echo date(“Y/m/d H:i:s”);?>
結果
2008/08/04 16:14:05
the_modified_date
12月 27th
エントリーの修正日付を出力します。投稿日時とは違うので注意。
<?php the_modified_date(); ?>
設置例
<?php the_modified_date(‘Y/n/j (D)’); ?>
表示例
2007/12/27 (木)
※引数はphpのdate()関数と同じ指定
the_time
12月 26th
エントリーの投稿時間を表示させる。
<?php the_time(); ?>
設定例
<?php the_time(‘Y/n/j (D)’); ?>
表示例
2007/12/25 (火)
※引数はphpのdate()関数と同じ指定
最近のコメント