Monday 2 February 2015

setTime - PHP

setTime

By using a date object we can set time to any value by using setTime property this format

setTime( Hour, minutes, seconds )

All above inputs are in integer. 
Here are some examples.
date_default_timezone_set('America/Chicago');
$date = new DateTime('2012-04-15 22:15:40');
echo $date->format('Y/m/d H:i:s') . "<br>";
$date->setTime(23,30);
echo $date->format('Y/m/d H:i:s') . "<br>";

The output is here
2012/04/15 22:15:40
2012/04/15 23:30:00
We can change the setTime to different values and output will change like this .
$date->setTime(2,50,32);
output is here
2012/04/15 22:15:40
2012/04/15 02:50:32

0 comments:

Post a Comment