The DateTimeInterface interface
(PHP 5 >= 5.5.0, PHP 7, PHP 8)
簡介
DateTimeInterface 的意思是可以約束型別為 DateTime 或 DateTimeImmutable。此介面不能讓使用者自己的 class 去實現(implements)。
類摘要
class DateTimeInterface
{
/* 常量 */
/* 方法 */
}預定義常量
DateTimeInterface::ATOM-
DATE_ATOM - Atom 格式(示例:2005-08-15T15:52:01+00:00)
-
DATE_COOKIE - HTTP Cookies 格式(示例: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 - RSS 格式(示例:2005-08-15T15:52:01+00:00)
更新日誌
| 版本 | 說明 |
|---|---|
| 7.2.0 | DateTime 的類常量現在定義在了 DateTimeInterface 上。 |
| 5.5.8 | 嘗試實現(implement)DateTimeInterface 時,會拋出嚴重錯誤。 之前此舉不會產生錯誤,但這種做法是不對的。 |
目錄
- DateTime::diff — Returns the difference between two DateTime objects
- DateTime::format — Returns date formatted according to given format
- DateTime::getOffset — Returns the timezone offset
- DateTime::getTimestamp — Gets the Unix timestamp
- DateTime::getTimezone — Return time zone relative to given DateTime
- DateTime::__wakeup — The __wakeup handler