PHP日付関数date UNIX時間の書式設定方法


この例では、PHP日付関数dateがUNIX時間をフォーマットする方法を説明します。皆さんの参考にしてください。具体的な分析は以下の通りです。
日付関数は、指定されたフォーマットに従ってunix時間を所望のテキスト出力にフォーマットすることができます。
関数文法は以下の通りです。

string date (string $Format);
string date (string $Format, int $Time);
以下はデモコードです。

<?php
echo "When this page was loaded,
"; echo 'It was then ', date ('r'), "
"; echo 'The currend date was ', date ('F j, Y'), "
"; echo 'The currend date was ', date ('M j, Y'), "
"; echo 'The currend date was ', date ('m/d/y'), "
"; echo 'The currend date was the ', date ('jS \o\f M, Y'), "
"; echo 'The currend time was ', date ('g:i:s A T'), "
"; echo 'The currend time was ', date ('H:i:s O'), "
"; echo date ('Y'); date ('L')?(print ' is'):(print ' is not'); echo " a leap year
"; echo time ('U'), " seconds had elapsed since January 1, 1970.
"; ?>
出力結果は以下の通りです

It was then Sat, 26 Dec 2009 07:09:51 +0000
The currend date was December 26, 2009
The currend date was Dec 26, 2009
The currend date was 12/26/09
The currend date was the 26th of Dec, 2009
The currend time was 7:09:51 AM GMT
The currend time was 07:09:51 +0000
2009 is not a leap year
1261811391 seconds had elapsed since January 1, 1970.
本論文で述べたように、皆さんのphpプログラムの設計に役に立ちます。