International PHP Conference 2015

The DateTimeImmutable class

(PHP 5 >= 5.5.0)

Introducere

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

Sinopsisul clasei

DateTimeImmutable implements DateTimeInterface {
/* Metode */
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 )
}

Cuprins

add a note add a note

User Contributed Notes 1 note

up
0
samundra dot shr at gmail dot com
7 months ago
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");
To Top