Share on Google+Share on Google+

date_time_set

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

Advertisements

Posted on: August 27, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.