Please note that DateTime:setDate() accepts out-of-range values without warnings.
EG:
<?php
date_default_timezone_set('Europe/London');
$datetime = new DateTime('2008-08-03 14:52:10');
$datetime->setDate(2008, 13, 12);
?>
will reset the DateTime object's date to now. The best approach is to make a wrapper to setDate() which do check for out-of-range values.
DateTime::setDate
(PHP 5 >= 5.2.0)
DateTime::setDate — Sets the date
Descrierea
Resets the current date of the DateTime object to a different date.
Parametri
- object
-
Doar pentru stilul procedural: Un obiect DateTime întors de funcţia date_create()
- year
-
Year of the date.
- month
-
Month of the date.
- day
-
Day of the date.
Valorile întroarse
Returns the modified DateTime.
Istoria schimbărilor
| Versiunea | Descriere |
|---|---|
| 5.3.0 | A fost schimbată valoarea întoarsă din NULL în DateTime. |
Exemple
Example #1 Object oriented example usage
<?php
date_default_timezone_set('Europe/London');
$datetime = new DateTime('2008-08-03 14:52:10');
$datetime->setDate(2008, 10, 12);
echo $datetime->format(DATE_RFC2822);
?>
Example #2 Procedural example usage
<?php
date_default_timezone_set('Europe/London');
$datetime = date_create('2008-08-03 14:52:10');
date_date_set($datetime, 2008, 10, 12);
echo date_format($datetime, DATE_RFC2822);
?>
Exemplul de mai sus va afişa:
Sun, 12 Oct 2008 14:52:10 +0100
DateTime::setDate
melicerte at mailinator dot com
12-Oct-2009 12:12
12-Oct-2009 12:12
