date_time_set alias DateTime::setTime function resets the the current time of the DateTime object to a different time. It returns the modified date and time.
date_time_set alias DateTime::setTime function resets the the current time of the DateTime object to a different time. It returns the modified date and time.
date_time_set alias DateTime::setTime function resets the the current time of the DateTime object to a different time. It returns the modified date and time.
Syntax
public DateTime DateTime::setTime ( int $hour , int $minute [, int $second ] )
DateTime date_time_set ( DateTime $object , int $hour , int $minute [, int $second ] )
Parameters
object - Procedural style only: A DateTime object returned by date_create()
hour - Hour of the time.
minute - Minute of the time.
second - Second of the time.
Example: Changing the time of a DateTime object
<?php
date_default_timezone_set('India/Delhi');
$datetime = new DateTime('2009-08-25 16:45:36');
echo $datetime->format('Y-m-d H:i:s') . "\n";
$datetime->setTime(13, 35, 12);
echo $datetime->format('Y-m-d H:i:s') . "\n";
$datetime->setTime($datetime->format('H'), $datetime->format('n') + 6);
echo $datetime->format('Y-m-d H:i:s') . "\n";
$datetime->setTime($datetime->format('H') + 12, $datetime->format('n'));
echo $datetime->format('Y-m-d H:i:s') . "\n";
?>