CakeFest 2024: The Official CakePHP Conference

Die Klasse DateTime

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

Einführung

Stellt Datum und Uhrzeit dar.

Diese Klasse verhält sich wie die Klasse DateTimeImmutable, außer dass die Objekte selbst verändert werden, wenn Modifizierungsmethoden wie DateTime::modify() aufgerufen werden.

Warnung

Der Aufruf von Methoden auf Objekten der Klasse DateTime verändert die in diesen Objekten gekapselten Informationen. Wenn das verhindert werden soll, muss der Operator clone verwendet werden, um ein neues Objekt zu erzeugen. Um dieses empfohlene Verhalten standardmäßig zu erhalten, sollte DateTimeImmutable anstelle von DateTime verwendet werden.

Klassenbeschreibung

class DateTime implements DateTimeInterface {
/* Geerbte Konstanten */
public const string DateTimeInterface::ATOM = "Y-m-d\\TH:i:sP";
public const string DateTimeInterface::COOKIE = "l, d-M-Y H:i:s T";
public const string DateTimeInterface::ISO8601 = "Y-m-d\\TH:i:sO";
public const string DateTimeInterface::ISO8601_EXPANDED = "X-m-d\\TH:i:sP";
public const string DateTimeInterface::RFC822 = "D, d M y H:i:s O";
public const string DateTimeInterface::RFC850 = "l, d-M-y H:i:s T";
public const string DateTimeInterface::RFC1036 = "D, d M y H:i:s O";
public const string DateTimeInterface::RFC1123 = "D, d M Y H:i:s O";
public const string DateTimeInterface::RFC7231 = "D, d M Y H:i:s \\G\\M\\T";
public const string DateTimeInterface::RFC2822 = "D, d M Y H:i:s O";
public const string DateTimeInterface::RFC3339 = "Y-m-d\\TH:i:sP";
public const string DateTimeInterface::RFC3339_EXTENDED = "Y-m-d\\TH:i:s.vP";
public const string DateTimeInterface::RSS = "D, d M Y H:i:s O";
public const string DateTimeInterface::W3C = "Y-m-d\\TH:i:sP";
/* Methoden */
public __construct(string $datetime = "now", ?DateTimeZone $timezone = null)
public add(DateInterval $interval): DateTime
public static createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null): DateTime|false
public static createFromImmutable(DateTimeImmutable $object): static
public modify(string $modifier): DateTime|false
public static __set_state(array $array): DateTime
public setDate(int $year, int $month, int $day): DateTime
public setISODate(int $year, int $week, int $dayOfWeek = 1): DateTime
public setTime(
    int $hour,
    int $minute,
    int $second = 0,
    int $microsecond = 0
): DateTime
public setTimestamp(int $timestamp): DateTime
public setTimezone(DateTimeZone $timezone): DateTime
public sub(DateInterval $interval): DateTime
public diff(DateTimeInterface $targetObject, bool $absolute = false): DateInterval
public format(string $format): string
public getOffset(): int
public getTimestamp(): int
public __wakeup(): void
}

Changelog

Version Beschreibung
7.2.0 Die Klassenkonstanten von DateTime sind nun in DateTimeInterface definiert.
7.1.0 Der Konstruktor von DateTime bezieht nun die aktuellen Mikrosekunden in den erzeugten Wert ein. Vorher wurden die Mikrosekunden immer mit 0 initialisiert.

Inhaltsverzeichnis

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top