前回の記事でdate()関数を使い表示処理を行いました。
現在の日時を調べてコード中の変数で利用するには、
getdate()関数を使うと便利です。
getdate()関数を使うと、日時に関する情報を格納した
配列を得ることができます。配列のキーは下記の通りです。
キー | 意味 | 範囲又は、例 |
---|---|---|
hours | 時 | 00~23 |
minutes | 分 | 00~59 |
seconds | 秒 | 00~59 |
year | 年 | 2015とか |
mon | 月 | 1~12 |
month | 月(英字) | January~December |
mday | 日 | 1~31 |
wday | 曜日(数値) | 0(日曜日)~6(土曜日) |
weekday | 曜日(英字) | Sunday~Saturday |
サンプルコードの実行結果はこちら
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<!doctype html> <html> <head> <meta charset="utf-8"> <title>日時を出力してみる</title> <link rel="stylesheet" href="../style.css"> </head> <body> <?php $format = array("hours","minutes","seconds","year","mon", "month","mday","wday","weekday"); ?> <table border="3"> <tr bgcolor="#b0b0b0"> <th>指定</th> <th>値</th> </tr> <?php $gt = getdate(); foreach( $format as $value ){ echo "<tr>"; echo "<td>{$value}</td>"; echo "<td>" . $gt[$value] . "</td>"; echo "</tr>"; } ?> </table> </body> </html> |