文字

The DateTimeImmutable class

(PHP 5 >= 5.5.0, PHP 7)

简介

This class behaves the same as DateTime except it never modifies itself but returns a new object instead.

类摘要

DateTimeImmutable implements DateTimeInterface {
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 ] )
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 )
}

Table of Contents

  • DateTimeImmutable::add — Adds an amount of days, months, years, hours, minutes and seconds
  • DateTimeImmutable::__construct — Returns new DateTimeImmutable object
  • DateTimeImmutable::createFromFormat — Returns new DateTimeImmutable object formatted according to the specified format
  • DateTimeImmutable::createFromMutable — Returns new DateTimeImmutable object encapsulating the given DateTime object
  • DateTimeImmutable::getLastErrors — Returns the warnings and errors
  • DateTimeImmutable::modify — Creates a new object with modified timestamp
  • DateTimeImmutable::__set_state — The __set_state handler
  • DateTimeImmutable::setDate — Sets the date
  • DateTimeImmutable::setISODate — Sets the ISO date
  • DateTimeImmutable::setTime — Sets the time
  • DateTimeImmutable::setTimestamp — Sets the date and time based on an Unix timestamp
  • DateTimeImmutable::setTimezone — Sets the time zone
  • DateTimeImmutable::sub — Subtracts an amount of days, months, years, hours, minutes and seconds

用户评论:

[#1] samundra dot shr at gmail dot com [2015-01-25 04:46:26]

Simple usage of DateTimeImmutable Class:

<?php
$format = "Y-m-d";
$dateString = "2015-01-25";

// Get new DateTimeImmutable Object
$date = DateTimeImmutable::createFromFormat($format,$dateString);

var_dump($date);

// DateTimeImmutable object can be used similar to DateTime object
echo $date->format("Y/m/d");

上一篇: 下一篇: