note 128265 added to datetimeimmutable.settimestamp

From: Date: Wed, 01 Mar 2023 08:51:45 +0000
Subject: note 128265 added to datetimeimmutable.settimestamp
Groups: php.notes 
Request: Send a blank email to php-notes+get-220222@lists.php.net to get a copy of this message
While modifying Datetime with the timezone, the user should be aware that changing the timestamp using "@".\time() is not the same as changing the timestamp using setTimestamp(). $now = new \DateTimeImmutable('August 30, 2023 09:00:00 GMT+01'); $origin = $now->getTimestamp(); // 1693382400 $usingAt = $now->modify('@'.$now->getTimestamp())->getTimestamp(); // 1693378800 $usingSetTimestamp = $now->setTimestamp($now->getTimestamp())->getTimestamp(); // 1693382400 var_dump($usingAt === $origin); // false var_dump($usingSetTimestamp === $origin); // true ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.130 (proxied: 2a01:4c8:46c:d5d1:f8ac:2719:54f:8e90) ---- Manual Page -- https://php.net/manual/en/datetimeimmutable.settimestamp.php Edit -- https://main.php.net/note/edit/128265 Del: integrated -- https://main.php.net/note/delete/128265/integrated Del: useless -- https://main.php.net/note/delete/128265/useless Del: bad code -- https://main.php.net/note/delete/128265/bad+code Del: spam -- https://main.php.net/note/delete/128265/spam Del: non-english -- https://main.php.net/note/delete/128265/non-english Del: in docs -- https://main.php.net/note/delete/128265/in+docs Del: other reasons-- https://main.php.net/note/delete/128265 Reject -- https://main.php.net/note/reject/128265 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220222) next »