Category Archives: PHP

DateTime::setTimestamp

It sets the date and time based on an Unix timestamp .
Example

<?php
$date = new DateTime();
echo $date->format(‘U = Y-m-d H:i:s’) . “<br />”;

$date->setTimestamp(1181503727);
echo $date->format(‘U = Y-m-d H:i:s’) ;
?>

Output

1335329861 = 2012-04-25 10:27:41
1181503727 = 2007-06-11 00:58:47

date_timestamp_set

Its an alias of DateTime::setTimestamp() and sets the date and time based on an Unix timestamp .
Example

<?php
$date1 = date_create();
echo date_format($date1, ‘U = Y-m-d H:i:s’).”<br />”;

date_timestamp_set($date1, 1171502325);
echo date_format($date1, ‘U = Y-m-d H:i:s’);
?>

Output

1335329740 = 2012-04-25 10:25:40
1171502325 = 2007-02-15 06:48:45

date_sunset

It returns time of sunset for a given day and location

Example

<?php
echo date(“D M d Y”). ‘, sunset time : ‘ .date_sunset(time(), SUNFUNCS_RET_STRING, 18.4, -19, 80, 2);
?>

Output

Wed Apr 25 2012, sunset time : 20:50

date_sunrise

It returns time of sunrise for a given day and location
Example

<?php
echo date(“D M d Y”). ‘, sunrise time : ‘ .date_sunrise(time(), SUNFUNCS_RET_STRING, 18.4, -19, 80, 2);
?>

Output

Tue Apr 24 2012, sunrise time : 09:38