PHP 8.4.2 Released!

Die Klasse DateTimeZone

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

Einführung

Stellt die Zeitzone dar.

Klassenbeschreibung

class DateTimeZone {
/* Konstanten */
public const int AFRICA;
public const int AMERICA;
public const int ANTARCTICA;
public const int ARCTIC;
public const int ASIA;
public const int ATLANTIC;
public const int AUSTRALIA;
public const int EUROPE;
public const int INDIAN;
public const int PACIFIC;
public const int UTC;
public const int ALL;
public const int ALL_WITH_BC;
public const int PER_COUNTRY;
/* Methoden */
public __construct(string $timezone)
public getName(): string
public getOffset(DateTimeInterface $datetime): int
public getTransitions(int $timestampBegin = PHP_INT_MIN, int $timestampEnd = PHP_INT_MAX): array|false
public static listAbbreviations(): array
public static listIdentifiers(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null): array
}

Vordefinierte Konstanten

DateTimeZone::AFRICA int

Afrikanische Zeitzonen

DateTimeZone::AMERICA int

Amerikanische Zeitzonen

DateTimeZone::ANTARCTICA int

Antarktische Zeitzonen

DateTimeZone::ARCTIC int

Arktische Zeitzonen

DateTimeZone::ASIA int

Asiatische Zeitzonen

DateTimeZone::ATLANTIC int

Atlantische Zeitzonen

DateTimeZone::AUSTRALIA int

Australische Zeitzonen

DateTimeZone::EUROPE int

Europäische Zeitzonen

DateTimeZone::INDIAN int

Indische Zeitzonen

DateTimeZone::PACIFIC int

Pazifische Zeitzonen

DateTimeZone::UTC int

UTC Zeitzonen

DateTimeZone::ALL int

Alle Zeitzonen

DateTimeZone::ALL_WITH_BC int

Alle Zeitzonen, auch abwärtskompatible

DateTimeZone::PER_COUNTRY int

Zeitzonen pro Land

Changelog

Version Beschreibung
8.4.0 Die Klassenkonstanten sind nun typisiert.

Inhaltsverzeichnis

add a note

User Contributed Notes 1 note

up
1
Jarmo Troska
1 year ago
Example of converting between timezones using the DateTime and DateTimeZone classes.

Note that PHP will also take care of calculating relevant daylight savings!

<?php

$utc_timezone
= new DateTimeZone("UTC");

$tallinn_timezone = new DateTimeZone("Europe/Tallinn");

// Create a new DateTime object in the UTC format

$datetime = new DateTime("2023-01-01 11:00:00", $utc_timezone);

// Convert the DateTime object to the timezone of Tallinn

$datetime->setTimezone($tallinn_timezone);

// Display the result in the YYYY-MM-DD HH:MM:SS format

echo $datetime->format('Y-m-d H:i:s');

// Returns: 2023-01-01 13:00:00

?>
To Top