Skip to content

Instantly share code, notes, and snippets.



Last active Jul 21, 2018
What would you like to do?
PHP examples
$t = date("H");
if ($t < 18) {
echo "Have a good day!";
else {echo "Good evening!";}
echo "\n";
echo "t = " . $t. " hours now\n";
echo "server timezone: " . date_default_timezone_get(), "\n";
$tz = timezone_open("Europe/Kiev");
$dt_bd = date_create('1975-09-08', $tz);
$t_off = date_offset_get($dt_bd);
echo "Kiev timezone offset: " . $t_off, "\n";
echo "Various date formats on server", "\n";
echo " date (DATE_RFC850): ", date (DATE_RFC850), "\n";
echo ' date("r"): ', date("r"), "\n";
$bd = mktime(1,1,0,9,8,1975);
echo "My birthday in sever time: ", date("r", $bd),"\n";
//print_r(timezone_identifiers_list(128, 'UA'));
$dt_tmp = date_create('now', $tz);
echo "Sep 8, 1975 in Kiev was on a ". date_format($dt_bd, 'r');
echo "\n";
$d_sunR = date_sunrise(time(),SUNFUNCS_RET_TIMESTAMP,$od_lat,$od_lon,90,1);
$d_sunS = date_sunset(time(),SUNFUNCS_RET_TIMESTAMP,$od_lat,$od_lon,90,1);
echo "Sun time in Odessa, Ukraine", "\n";
echo "Date: ";
echo date_format(date_timestamp_set($dt_tmp, time()), "r"), "\n";
echo "Sunrise time: ";
echo date_format(date_timestamp_set($dt_tmp, $d_sunR),"r"), "\n";
echo "Sunset time: ";
echo date_format(date_timestamp_set($dt_tmp, $d_sunS),"r"), "\n\n";
// $sun_info=date_sun_info(strtotime("2013-01-01"),31.7667,35.2333);
foreach ($sun_info as $key=>$val)
echo "$key: " . date_format(date_timestamp_set($dt_tmp, $val),"H:i:s") . "<br>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment