The DateTimeInterface interface

(PHP 5 >= 5.5.0, PHP 7)

Вступ

DateTimeInterface is meant so that both DateTime and DateTimeImmutable can be type hinted for. It is not possible to implement this interface with userland classes.

Короткий Огляд Класа

DateTimeInterface {
/* Методи */
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 )
}

Журнал Змін

Версія Опис
5.5.8 Trying to implement DateTimeInterface raises a fatal error now. Formerly implementing the interface didn't raise an error, but the behavior was erroneous.

Зміст

add a note add a note

User Contributed Notes 1 note

up
3
divinity76 at gmail dot com
2 years ago
if you want to know what all the constants looks like, try

<?php
$constants
= (new ReflectionClass("DateTimeInterface"))->getConstants();
foreach(
$constants as $name => $format){
    echo
"{$name}: " . date($format, 0) . "\n";
}
?>

in php 8.0.3 it prints:

ATOM: 1970-01-01T01:00:00+01:00
COOKIE: Thursday, 01-Jan-1970 01:00:00 CET
ISO8601: 1970-01-01T01:00:00+0100
RFC822: Thu, 01 Jan 70 01:00:00 +0100
RFC850: Thursday, 01-Jan-70 01:00:00 CET
RFC1036: Thu, 01 Jan 70 01:00:00 +0100
RFC1123: Thu, 01 Jan 1970 01:00:00 +0100
RFC7231: Thu, 01 Jan 1970 01:00:00 GMT
RFC2822: Thu, 01 Jan 1970 01:00:00 +0100
RFC3339: 1970-01-01T01:00:00+01:00
RFC3339_EXTENDED: 1970-01-01T01:00:00.000+01:00
RSS: Thu, 01 Jan 1970 01:00:00 +0100
W3C: 1970-01-01T01:00:00+01:00
To Top