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

search for in the

DateTime::setTimezone> <DateTime::setTime
Last updated: Fri, 20 Nov 2009

view this page in

DateTime::setTimestamp

(PHP 5 >= 5.3.0)

DateTime::setTimestampSets the date and time based on an Unix timestamp

Description

public DateTime DateTime::setTimestamp ( int $unixtimestamp )

Sets the date and time based on an Unix timestamp.

Parameters

unixtimestamp

Unix timestamp representing the date.

Return Values

Returns the modified DateTime.

See Also



add a note add a note User Contributed Notes
DateTime::setTimestamp
edwin dot h at clear dot net dot nz
01-Oct-2009 11:55
If you are using PHP < 5.3.0 you can use this function instead:

<?php
function DateTime_setTimestamp(&$dt,$timestamp) {
$dtz_original = $dt -> getTimezone();
$dtz_utc = new DateTimeZone("UTC");
$dt -> setTimezone($dtz_utc);
$year = gmdate("Y",$timestamp);
$month = gmdate("n",$timestamp);
$day = gmdate("j",$timestamp);
$hour = gmdate("G",$timestamp);
$minute = gmdate("i",$timestamp);
$second = gmdate("s",$timestamp);
$dt -> setDate($year,$month,$day);
$dt -> setTime($hour,$minute,$second);
$dt -> setTimezone($dtz_original);
}
?>

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