downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DateTime::setTimestamp> <DateTime::setISODate
Last updated: Fri, 20 Nov 2009

view this page in

DateTime::setTime

(PHP 5 >= 5.2.0)

DateTime::setTimeSets the time

Descrierea

public DateTime DateTime::setTime ( int $hour , int $minute [, int $second ] )
DateTime date_time_set ( DateTime $object , int $hour , int $minute [, int $second ] )

Resets the current time of the DateTime object to a different time.

Parametri

object

Doar pentru stilul procedural: Un obiect DateTime întors de funcţia date_create()

hour

Hour of the time.

minute

Minute of the time.

second

Second of the time.

Valorile întroarse

Returns the modified DateTime.

Istoria schimbărilor

Versiunea Descriere
5.3.0A fost schimbată valoarea întoarsă din NULL în DateTime.

Exemple

Example #1 Changing the time of a DateTime object

<?php
date_default_timezone_set
('Europe/London');

$datetime = new DateTime('2008-08-03 12:35:23');
echo 
$datetime->format('Y-m-d H:i:s') . "\n";

$datetime->setTime(145524);
echo 
$datetime->format('Y-m-d H:i:s') . "\n";

// Warning: Does not increment the hour!
// This is because the hour has been set (14) - see date_modify()
$datetime->setTime($datetime->format('H'), $datetime->format('n') + 6);
echo 
$datetime->format('Y-m-d H:i:s') . "\n";

// *Does* increment the day, because the day has not been set
$datetime->setTime($datetime->format('H') + 12$datetime->format('n'));
echo 
$datetime->format('Y-m-d H:i:s') . "\n";
?>

Exemplul de mai sus va afişa:

2008-08-03 12:35:23
2008-08-03 14:55:24
2008-08-03 14:14:00
2008-08-04 02:08:00

Vedeţi de asemenea



add a note add a note User Contributed Notes
DateTime::setTime
There are no user contributed notes for this page.

DateTime::setTimestamp> <DateTime::setISODate
Last updated: Fri, 20 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites