DateTime 类
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
简介
日期和时间表示。
此类与 DateTimeImmutable 行为相同。区别就是调用有修改行为的方法(比如 DateTime::modify())时,会修改对象本身。
警告
在 DateTime 类的对象上调用方法会改变对象中封装的信息,如果想要避免这种情况,就得使用
clone
操作符创建新的对象。推荐使用 DateTimeImmutable
代替 DateTime 来获得这个默认行为。
类摘要
/* 继承的常量 */
/* 方法 */
public static createFromFormat(string
}$format
, string $datetime
, ?DateTimeZone $timezone
= null
): DateTime|false更新日志
版本 | 说明 |
---|---|
8.4.0 | 类常量现已类型化。 |
7.2.0 | DateTime 的类常量现在定义在 DateTimeInterface 上。 |
7.1.0 |
现在 DateTime 构造器在构造值中包含了当前微秒。在此之前,微秒会一直初始化为 0 。
|
目录
- DateTime::add — 修改 DateTime 对象,增加天、月、年、小时、分钟以及秒的数量。
- DateTime::__construct — 返回新的 DateTime 对象
- DateTime::createFromFormat — 根据指定格式解析时间字符串
- DateTime::createFromImmutable — Returns new DateTime instance encapsulating the given DateTimeImmutable object
- DateTime::createFromInterface — Returns new DateTime object encapsulating the given DateTimeInterface object
- DateTime::getLastErrors — 别名 DateTimeImmutable::getLastErrors
- DateTime::modify — 修改日期时间对象的值
- DateTime::__set_state — __set_state 处理程序
- DateTime::setDate — 设置日期
- DateTime::setISODate — 设置 ISO 日期
- DateTime::setTime — 设置时间
- DateTime::setTimestamp — 以 Unix 时间戳的方式设置日期和时间
- DateTime::setTimezone — 设置 DateTime 对象的时区
- DateTime::sub — 对 DateTime 对象减去一定量的日、月、年、小时、分钟和秒。
+添加备注
用户贡献的备注
此页面尚无用户贡献的备注。