哈希空间 Ctrl + F 进行搜索
首页 php手册中文版 CSS中文手册 哈希文档 Markdown在线工具

PHP datetimeinterface 组件

The DateTimeInterface interface

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

简介

创建 DateTimeInterface 是为了让参数、返回值、属性类型声明能够接受 DateTimeImmutableDateTime 作为值。不可以使用用户定义的类实现该接口。

此接口也定义了公共常量,允许通过 DateTimeImmutable::format()DateTime::format() 格式化 DateTimeImmutableDateTime 对象。

接口摘要

interface 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 ISO8601_EXPANDED = "X-m-d\TH:i:sP";
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
public format(string $format): string
public getOffset(): int
public getTimestamp(): int
public getTimezone(): DateTimeZone|false
public __wakeup(): void
}

预定义常量

DateTimeInterface::ATOM
DATE_ATOM
Atom 格式(示例:2005-08-15T15:52:01+00:00)
DateTimeInterface::COOKIE
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 兼容的格式,请使用 DateTimeInterface::ISO8601_EXPANDEDDateTimeInterface::ATOM 两个常量。

DateTimeInterface::ISO8601_EXPANDED
DATE_ISO8601_EXPANDED
ISO-8601 扩大版(示例:+10191-07-26T08:59:52+01:00)

注意: 通过始终包含符号字符,此格式允许超出 ISO-8601 正常范围(0000-9999)的年份。还解决了时区部分(+01:00)与 ISO-8601 兼容的问题。

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 格式(示例: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)

更新日志

版本 说明
8.2.0 新增常量 DateTimeInterface::ISO8601_EXPANDED
7.2.0 DateTime 的类常量现在定义在了 DateTimeInterface 上。

目录

打开 哈希空间 微信小程序中查看更佳