PHP
日期和时间 | Date and Time

DateTimeImmutable (class)

The DateTimeImmutable class

Introduction

(PHP 5 >= 5.5.0, PHP 7)

这个类的行为与DateTime相同,除了它从不修改自身,而是返回一个新的对象。

课程简介

DateTimeImmutable implements DateTimeInterface {

/* Methods */

public __construct ([ string $time = "now" [, DateTimeZone $timezone = NULL ]] )

public DateTimeImmutable add ( DateInterval $interval )

public static DateTimeImmutable createFromFormat ( string $format , string $time [, DateTimeZone $timezone ] )

public static DateTimeImmutable createFromMutable ( DateTime $datetime )

public static array getLastErrors ( void )

public DateTimeImmutable modify ( string $modify )

public static DateTimeImmutable __set_state ( array $array )

public DateTimeImmutable setDate ( int $year , int $month , int $day )

public DateTimeImmutable setISODate ( int $year , int $week [, int $day = 1 ] )

public DateTimeImmutable setTime ( int $hour , int $minute [, int $second = 0 [, int $microseconds = 0 ]] )

public DateTimeImmutable setTimestamp ( int $unixtimestamp )

public DateTimeImmutable setTimezone ( DateTimeZone $timezone )

public DateTimeImmutable sub ( DateInterval $interval )

public DateInterval diff ( DateTimeInterface $datetime2 [, bool $absolute = false ] )

public string format ( string $format )

public int getOffset ( void )

public int getTimestamp ( void )

public DateTimeZone getTimezone ( void )

public __wakeup ( void )

}

目录

  • DateTimeImmutable :: add - 添加天数,月数,年数,小时数,分钟数和秒数

  • DateTimeImmutable :: __构造 - 返回新的DateTimeImmutable对象

  • DateTimeImmutable :: createFromFormat - 根据指定的格式分析时间字符串

  • DateTimeImmutable :: createFromMutable - 返回封装给定DateTime对象的新DateTimeImmutable对象

  • DateTimeImmutable :: getLastErrors - 返回警告和错误

  • DateTimeImmutable :: modify - 使用修改的时间戳创建一个新对象

  • DateTimeImmutable :: __ set_state - __set_state处理程序

  • DateTimeImmutable :: setDate - 设置日期

  • DateTimeImmutable :: setISODate - 设置ISO日期

  • DateTimeImmutable :: setTime - 设置时间

  • DateTimeImmutable :: setTimestamp - 根据Unix时间戳设置日期和时间

  • DateTimeImmutable :: setTimezone - 设置时区

  • DateTimeImmutable :: sub - 减去天数,月数,年数,小时数,分钟数和秒数

← DateTime::sub

DateTimeImmutable::add →