Skip to content

Instantly share code, notes, and snippets.

@alogic0
Last active July 21, 2018 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alogic0/6381941307c960f8cab60aba4d4b8c2d to your computer and use it in GitHub Desktop.
Save alogic0/6381941307c960f8cab60aba4d4b8c2d to your computer and use it in GitHub Desktop.
PHP examples
// http://sandbox.onlinephpfunctions.com/code/d1983f5ae45977a035bfb54a9d8782c74c69833c
<?php
$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'));
$od_lat=46.485722;
$od_lon=30.743444;
$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);
$sun_info=date_sun_info(time(),$od_lat,$od_lon);
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