note 107356 added to datetime.modify
| From: | kavi at postpro dot net | Date: | Fri, 03 Feb 2012 01:19:01 +0000 |
| Subject: | note 107356 added to datetime.modify | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185835@lists.php.net to get a copy of this message | ||
As of PHP 5.3.3, this is definitely a limited subset of strtotime()'s features. Specifically,
calculating from midnight is not supported.
$x = new DateTime('2007-04-02 17:45:00', new DateTimeZone('America/New_York'));
print_r($x);
echo "x timestamp: " . $x->getTimestamp() . ' ' .
$x->format('Y-m-d H:i:s') . "\n";
$b = clone $x;
$b->modify('+1 second');
echo "x +1 second: " . $b->getTimestamp() . ' ' .
$b->format('Y-m-d H:i:s') . "\n";
$c = clone $x;
$c->modify('midnight');
echo "x's midnight: " . $c->getTimestamp() . ' ' .
$c->format('Y-m-d H:i:s') . "\n";
$c = clone $x;
$c->modify('midnight +1 day');
echo "x's midnight +1 day: " . $c->getTimestamp() . ' ' .
$c->format('Y-m-d H:i:s') . "\n";
$x->modify('midnight tomorrow');
echo "x midnight tomorrow: " . $x->getTimestamp() . ' ' .
$x->format('Y-m-d H:i:s') . "\n";
$x->modify('midnight tonight');
echo "x midnight tonight: " . $x->getTimestamp() . ' ' .
$x->format('Y-m-d H:i:s') . "\n";
$x->modify('-1 second');
echo "x minus 1 second: " . $x->getTimestamp() . ' ' .
$x->format('Y-m-d H:i:s') . "\n";
results:
DateTime Object
(
[date] => 2007-04-02 17:45:00
[timezone_type] => 3
[timezone] => America/New_York
)
x timestamp: 1175550300 2007-04-02 17:45:00
x +1 second: 1175550301 2007-04-02 17:45:01
x's midnight: 1175550300 2007-04-02 17:45:00
x's midnight +1 day: 1175636700 2007-04-03 17:45:00
x midnight tomorrow: 1175636700 2007-04-03 17:45:00
x midnight tonight: 1175636700 2007-04-03 17:45:00
x minus 1 second: 1175636699 2007-04-03 17:44:59
----
Server IP: 64.71.164.2
Probable Submitter: 64.242.113.237
----
Manual Page -- http://www.php.net/manual/en/datetime.modify.php
Edit -- https://master.php.net/note/edit/107356
Del: integrated -- https://master.php.net/note/delete/107356/integrated
Del: useless -- https://master.php.net/note/delete/107356/useless
Del: bad code -- https://master.php.net/note/delete/107356/bad+code
Del: spam -- https://master.php.net/note/delete/107356/spam
Del: non-english -- https://master.php.net/note/delete/107356/non-english
Del: in docs -- https://master.php.net/note/delete/107356/in+docs
Del: other reasons-- https://master.php.net/note/delete/107356
Reject -- https://master.php.net/note/reject/107356
Search -- https://master.php.net/manage/user-notes.php