Home Tutorial Php Phpdate date_time_set

 
 

date_time_set
Posted on: August 27, 2009 at 12:00 AM
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

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";
?>

Related Tags for date_time_set:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.