(PHP 5 >= 5.5.0, PHP 7)
はじめに
DateTimeInterface は、DateTime および DateTimeImmutable をタイプヒントで使えるようにするためのインターフェイスです。 このインターフェイスを実装したクラスをユーザー側で作ることはできません。
クラス概要
DateTimeInterface {
const
string
ATOM
= "Y-m-d\TH:i:sP"
const
string
COOKIE
= "l, d-M-Y H:i:s T"
const
string
ISO8601
= "Y-m-d\TH:i:sO"
const
string
RFC822
= "D, d M y H:i:s O"
const
string
RFC850
= "l, d-M-y H:i:s T"
const
string
RFC1036
= "D, d M y H:i:s O"
const
string
RFC1123
= "D, d M Y H:i:s O"
const
string
RFC7231
= "D, d M Y H:i:s \G\M\T"
const
string
RFC2822
= "D, d M Y H:i:s O"
const
string
RFC3339
= "Y-m-d\TH:i:sP"
const
string
RFC3339_EXTENDED
= "Y-m-d\TH:i:s.vP"
const
string
RSS
= "D, d M Y H:i:s O"
const
string
W3C
= "Y-m-d\TH:i:sP"
/* メソッド */
public diff
( DateTimeInterface $targetObject
[, bool $absolute
= false
] ) : DateInterval|false
public format
( string $format
) : string|false
public getOffset ( ) : int|false
public getTimestamp ( ) : int
public getTimezone ( ) : DateTimeZone|false
public __wakeup ( )
}
定義済み定数
DateTimeInterface::ATOM
DATE_ATOM
- Atom (例: 2005-08-15T15:52:01+00:00)
DateTimeInterface::COOKIE
DATE_COOKIE
- HTTP Cookie (例: Monday, 15-Aug-2005 15:52:01 UTC)
DateTimeInterface::ISO8601
DATE_ISO8601
ISO-8601 (例: 2005-08-15T15:52:01+0000)
注意:
このフォーマットは、ISO-8601 と互換性がありません。 しかし、後方互換性を保つために残されています。 ISO-8601 と互換性を保つためには、
DateTime::ATOM
またはDATE_ATOM
を使うようにしてください。DateTimeInterface::RFC822
DATE_RFC822
- RFC 822 (例: Mon, 15 Aug 05 15:52:01 +0000)
DateTimeInterface::RFC850
DATE_RFC850
- RFC 850 (例: Monday, 15-Aug-05 15:52:01 UTC)
DateTimeInterface::RFC1036
DATE_RFC1036
- RFC 1036 (例: Mon, 15 Aug 05 15:52:01 +0000)
DateTimeInterface::RFC1123
DATE_RFC1123
- RFC 1123 (例: Mon, 15 Aug 2005 15:52:01 +0000)
DateTimeInterface::RFC7231
DATE_RFC7231
- RFC 7231 (PHP 7.0.19 と 7.1.5以降) (例: Sat, 30 Apr 2016 17:52:13 GMT)
DateTimeInterface::RFC2822
DATE_RFC2822
- RFC 2822 (例: Mon, 15 Aug 2005 15:52:01 +0000)
DateTimeInterface::RFC3339
DATE_RFC3339
-
DATE_ATOM
と同じです (PHP 5.1.3 以降) DateTimeInterface::RFC3339_EXTENDED
DATE_RFC3339_EXTENDED
- RFC 3339 EXTENDED フォーマット (PHP 7.0.0 以降) (例: 2005-08-15T15:52:01.000+00:00)
DateTimeInterface::RSS
DATE_RSS
- RSS (例: Mon, 15 Aug 2005 15:52:01 +0000)
DateTimeInterface::W3C
DATE_W3C
- World Wide Web Consortium (例: 2005-08-15T15:52:01+00:00)
変更履歴
バージョン | 説明 |
---|---|
7.2.0 | DateTime クラスの定数は、
DateTimeInterface で定義されるようになりました。 |
5.5.8 | DateTimeInterface を実装しようとすると fatal error が発生するようになりました。
それまでのバージョンではエラーは発生しませんでしたが、その挙動は間違ったものでした。 |
目次
- DateTime::diff — ふたつの DateTime オブジェクトの差を返す
- DateTime::format — 指定した書式でフォーマットした日付を返す
- DateTime::getOffset — タイムゾーンのオフセットを返す
- DateTime::getTimestamp — Unix タイムスタンプを取得する
- DateTime::getTimezone — 指定した DateTime に関連するタイムゾーンを返す
- DateTime::__wakeup — __wakeup ハンドラ
/* 定数 */