PEAR::Date1.4.7リリース
ありがちな日付クラスですが、基本となるクラスだけあって、結構使えます。PHP4.3以降で利用可能です。
たとえばタイムゾーンの変更は、以下のような感じに書けます。便利〜!
<?php error_reporting(E_ALL); require_once 'Date.php'; require_once 'Date/TimeZone.php'; /** * 現在時刻(JST) */ $now = new Date(); var_dump($now->getDate()); /** * タイムゾーンを'Canada/Pacific'に変更 */ $now->convertTZ(new Date_TimeZone('Canada/Pacific')); //$now->convertTZbyID('Canada/Pacific'); // これでもOK var_dump($now->getDate()); /** * タイムゾーンを'CET'に変更 */ $now->convertTZ(new Date_TimeZone('CET')); //$now->convertTZbyID('CET'); // これでもOK var_dump($now->getDate()); /** * タイムゾーンを'UTC'に変更 */ $now->toUTC(); var_dump($now->getDate());
グローバルに(死語?)利用されるサービスとかを構築する場合、重宝するかも知れません。
Generic classes for representation and manipulation of dates, times and time zones without the need of timestamps, which is a huge limitation for php programs. Includes time zone data, time zone conversions and many date/time conversions.