the getTimestamp() function and the format("U") function for get the timestamp from a DateTime object, first convert the object in UTC TimeZone, and then give the timestamp int.
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
DateTimeInterface::getTimezone -- DateTimeImmutable::getTimezone -- DateTime::getTimezone -- date_timezone_get — Return time zone relative to given DateTime
Stile orientato agli oggetti
Stile procedurale
Return time zone relative to given DateTime.
oggetto
Solo per lo stile procedurale: Un oggetto DateTime restituito da date_create()
Returns a DateTimeZone object on success
o false
in caso di fallimento.
Example #1 DateTime::getTimezone() example
Stile orientato agli oggetti
<?php
$date = new DateTimeImmutable(null, new DateTimeZone('Europe/London'));
$tz = $date->getTimezone();
echo $tz->getName();
?>
Stile procedurale
<?php
$date = date_create(null, timezone_open('Europe/London'));
$tz = date_timezone_get($date);
echo timezone_name_get($tz);
?>
I precedenti esempi visualizzeranno:
Europe/London
the getTimestamp() function and the format("U") function for get the timestamp from a DateTime object, first convert the object in UTC TimeZone, and then give the timestamp int.