date_timestamp_getGETS the
UNIX timestamp.
<?php
/* - - - - - - - - - - - - - - - - - - -
Object oriented style I
- - - - - - - - - - - - - - - - - - - */
int public DateTime::getTimestamp ( )
?>
<?php
/* - - - - - - - - - - - - - - - - - - - -
Object oriented style II
- - - - - - - - - - - - - - - - - - - - */
int public DateTimeImmutable::getTimestamp ( )
?>
<?php
/* - - - - - - - - - - - - - - - - - - -
Object oriented style I
- - - - - - - - - - - - - - - - - - - */
int public DateTimeInterface::getTimestamp ( )
?>
<?php
/* - - - - - - - - - - - - - - - - -
Procedural style II
- - - - - - - - - - - - - - - - - */
int date_timestamp_get ( DateTimeInterface $object )
where
$object = The DateTimeInterface object
?>
For Procedural style, only: A DateTime object returned by the function date_create.
The function modifies this object.
The DateTime object for method chaining or FALSE on failure, except in PHP 8.0.0..
DateTimeInterface is meant so that both DateTime and DateTimeImmutable can be type hinted for.
It is not possible to implement this interface with userland classes.
EXERCISE
<?php
date_default_timezone_set("UTC");
$dftz011 = date_default_timezone_get();
echo '<br>' . $dftz011 . '<br><br>';
$dtmg011 = new DateTime();
$dtmg011->getTimestamp();
echo $dtmg011->format('B => (U) => T Y-M-d H:i:s');
?>
EXERCISE
<?php
date_default_timezone_set("America/New_York");
$dftz021 = date_default_timezone_get();
echo '<br>' . $dftz021 . '<br><br>';
$dtmg021 = date_create();
date_timestamp_get($dtmg021);
echo date_format($dtmg021, 'B => (U) => T Y-M-d H:i:s');
?>
EXERCISE
<?php
$arrtz03 = timezone_identifiers_list();
$cnt03 = (count($arrtz03) - 1);
$rd03 = mt_rand(0, $cnt03);
$tzn03 = $arrtz03[$rd03];
date_default_timezone_set($tzn03);
$dftz031 = date_default_timezone_get();
echo '<br>' . $dftz031 . '<br><br>';
$dcnw03 = time();
$strf03 = "%Y-%m-%d %H:%M:%S";
$fpt_d03 = strftime($strf03, $dcnw03);
$d103 = new DateTime($fpt_d03, new DateTimeZone($dftz031));
$t103 = $d103->getTimestamp();
$dtmg031 = date_create();
date_timestamp_get($dtmg031);
echo date_format($dtmg031, 'B => (U) => T Y-M-d H:i:s');
?>
EXERCISE
<?php
$arrtz04 = timezone_identifiers_list();
$cnt04 = (count($arrtz04) - 1);
$rd04 = mt_rand(0, $cnt04);
$tzn04 = $arrtz04[$rd04];
date_default_timezone_set($tzn04);
$dftz041 = date_default_timezone_get();
echo '<br>' . $dftz041 . '<br><br>';
$dcnw04 = time();
$strf04 = "%Y-%m-%d %H:%M:%S";
$fpt_d04 = strftime($strf04, $dcnw04);
$d104 = new DateTimeImmutable($fpt_d04, new DateTimeZone($dftz041));
$t104 = $d104->getTimestamp();
$dtmg041 = date_create();
date_timestamp_get($dtmg041);
echo date_format($dtmg041, 'B => (U) => T Y-M-d H:i:s');
?>