Das DateTimeInterface-Interface

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

Einführung

Das DateTimeInterface wurde eingeführt, damit Parameter-, Rückgabe- oder Eigenschaftstyp-Deklarationen entweder DateTimeImmutable oder DateTime als Wert annehmen können. Es ist nicht möglich, dieses Interface in benutzerdefinierten Klassen zu implementieren.

Gemeinsame Konstanten, die es ermöglichen, DateTimeImmutable- oder DateTime-Objekte durch DateTimeImmutable::format() und DateTime::format() zu formatieren, sind in diesem Interface ebenfalls definiert.

Interface-Übersicht

interface DateTimeInterface {
/* Konstanten */
const string ATOM = "Y-m-d\TH:i:sP";
const string COOKIE = "l, d-M-Y H:i:s T";
const string ISO8601 = "Y-m-d\TH:i:sO";
const string ISO8601_EXPANDED = "X-m-d\TH:i:sP";
const string RFC822 = "D, d M y H:i:s O";
const string RFC850 = "l, d-M-y H:i:s T";
const string RFC1036 = "D, d M y H:i:s O";
const string RFC1123 = "D, d M Y H:i:s O";
const string RFC7231 = "D, d M Y H:i:s \G\M\T";
const string RFC2822 = "D, d M Y H:i:s O";
const string RFC3339 = "Y-m-d\TH:i:sP";
const string RFC3339_EXTENDED = "Y-m-d\TH:i:s.vP";
const string RSS = "D, d M Y H:i:s O";
const string W3C = "Y-m-d\TH:i:sP";
/* Methoden */
public diff(DateTimeInterface $targetObject, bool $absolute = false): DateInterval
public format(string $format): string
public getOffset(): int
public getTimestamp(): int
public getTimezone(): DateTimeZone|false
public __wakeup(): void
}

Vordefinierte Konstanten

DateTimeInterface::ATOM
DATE_ATOM
Atom (Beispiel: 2005-08-15T15:52:01+00:00)
DateTimeInterface::COOKIE
DATE_COOKIE
HTTP-Cookies (Beispiel: Monday, 15-Aug-05 15:52:01 UTC)
DateTimeInterface::ISO8601
DATE_ISO8601
ISO-8601 (Beispiel: 2005-08-15T15:52:01+0000)

Hinweis: Dieses Format ist nicht kompatibel zu ISO-8601, wird aber aus Gründen der Abwärtskompatibilität so belassen. Für ISO-8601-Kompatibilität sollte stattdessen DateTimeInterface::ISO8601_EXPANDED oder DateTimeInterface::ATOM verwendet werden.

DateTimeInterface::ISO8601_EXPANDED
DATE_ISO8601_EXPANDED
ISO-8601 erweitert (Beispiel: +10191-07-26T08:59:52+01:00)

Hinweis: Dadurch, dass dieses Format immer ein Vorzeichen enthält, können Jahresangaben außerhalb des normalen Bereichs von ISO-8601 (0000-9999) angegeben werden. Es berücksichtigt außerdem, dass der Teil mit der Zeitzone (+01:00) mit ISO-8601 kompatibel ist.

DateTimeInterface::RFC822
DATE_RFC822
RFC 822 (Beispiel: Mon, 15 Aug 05 15:52:01 +0000)
DateTimeInterface::RFC850
DATE_RFC850
RFC 850 (Beispiel: Monday, 15-Aug-05 15:52:01 UTC)
DateTimeInterface::RFC1036
DATE_RFC1036
RFC 1036 (Beispiel: Mon, 15 Aug 05 15:52:01 +0000)
DateTimeInterface::RFC1123
DATE_RFC1123
RFC 1123 (Beispiel: Mon, 15 Aug 2005 15:52:01 +0000)
DateTimeInterface::RFC7231
DATE_RFC7231
RFC 7231 (seit PHP 7.0.19 und 7.1.5) (Beispiel: Sat, 30 Apr 2016 17:52:13 GMT)
DateTimeInterface::RFC2822
DATE_RFC2822
RFC 2822 (Beispiel: Mon, 15 Aug 2005 15:52:01 +0000)
DateTimeInterface::RFC3339
DATE_RFC3339
Genau wie DATE_ATOM
DateTimeInterface::RFC3339_EXTENDED
DATE_RFC3339_EXTENDED
RFC 3339 EXTENDED Format (Beispiel: 2005-08-15T15:52:01.000+00:00)
DateTimeInterface::RSS
DATE_RSS
RSS (Beispiel: Mon, 15 Aug 2005 15:52:01 +0000)
DateTimeInterface::W3C
DATE_W3C
World Wide Web Consortium (Beispiel: 2005-08-15T15:52:01+00:00)

Changelog

Version Beschreibung
8.2.0 Die Konstante DateTimeInterface::ISO8601_EXPANDED wurde hinzugefügt.
7.2.0 Die Klassenkonstanten von DateTime sind nun in DateTimeInterface definiert.

Inhaltsverzeichnis

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

How to celebrate a birthday in Berlin in an unusual way?

How is it organized? Is the route fixed or can you choose your own? I wonder how long the whole trip takes and are there any restrictions? ​

Geschrieben von einermeiner am 31.03.2025 23:47:53
Forum: Apps und PHP Script Gesuche
How to celebrate a birthday in Berlin in an unusual way?

Riding around Berlin with friends, enjoying drinks and fun is a great idea for a holiday or just a nice day out. This format is great for companie ...

Geschrieben von daberty am 31.03.2025 23:46:24
Forum: Apps und PHP Script Gesuche
How to celebrate a birthday in Berlin in an unusual way?

This year I want to do something out of the ordinary, not just sit in a bar. I think to gather friends and make the holiday more active, perhaps w ...

Geschrieben von einermeiner am 31.03.2025 23:38:10
Forum: Apps und PHP Script Gesuche
Google reCAPTCHA in Kontaktformular einbinden

json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secret."&response=".$captcha), true) eine gültige Antwor ...

Geschrieben von lauralorde am 31.03.2025 09:08:16
Forum: PHP Developer Forum