A interface DateTimeInterface

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

Introdução

A interface DateTimeInterface é destinada para que DateTime e DateTimeImmutable possam fazer indução de tipo. Não é possível implementar essas interfaces em classes no espaço do usuário.

Sinopse da classe

DateTimeInterface {
/* Métodos */
public diff ( DateTimeInterface $datetime2 , bool $absolute = false ) : DateInterval
public format ( string $format ) : string
public getOffset ( ) : int
public getTimestamp ( ) : int
public __wakeup ( )
}

Changelog

Versão Descrição
5.5.8 Tentar implementar DateTimeInterface, lançará um erro fatal. Anteriormente, implementar a interface não lançava erro, porém, o comportamento estava incorreto.

Índice

add a note add a note

User Contributed Notes 1 note

up
0
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