In the timezones you can use the newer versions “America/New_York”, “America/Phoenix”, or the older versions “US/Eastern”, “US/Pacific”, “US/Hawaii” …
Note that America is the continent, not the country USA… so Hawaii which is not on that continent but rather in the pacific, would be “Pacific/Honolulu”.
I changed the code a bit (added an out_time function I was playing with, and hacked it too)
New output
24 Hour Mode
`Today:
Sunrise: 05:55
Sunset: 19:04
Civilian Twilight start: 05:30
Civilian Twilight end: 19:28
Nautical Twilight start: 05:00
Nautical Twilight end: 19:59
Astronomical Twilight start: 04:28
Astronomical Twilight end: 20:30
Length of Visible Light: 13:58
Length of Day: 13:09
Tommorrow:
Sunrise: 05:56
Sunset: 19:02
Civilian Twilight start: 05:31
Civilian Twilight end: 19:27
Nautical Twilight start: 05:01
Nautical Twilight end: 19:57
Astronomical Twilight start: 04:29
Astronomical Twilight end: 20:29
Length of Visible Light: 13:56
Length of Day: 13:06
Diff Visable Light from Yesterday: -2 mins
Diff Length of day from Yesterday: -3 mins`
12 hour Mode
`Today:
Sunrise: 5:55 am
Sunset: 7:04 pm
Civilian Twilight start: 5:30 am
Civilian Twilight end: 7:28 pm
Nautical Twilight start: 5:00 am
Nautical Twilight end: 7:59 pm
Astronomical Twilight start: 4:28 am
Astronomical Twilight end: 8:30 pm
Length of Visible Light: 1:58 pm
Length of Day: 1:09 pm
Tommorrow:
Sunrise: 5:56 am
Sunset: 7:02 pm
Civilian Twilight start: 5:31 am
Civilian Twilight end: 7:27 pm
Nautical Twilight start: 5:01 am
Nautical Twilight end: 7:57 pm
Astronomical Twilight start: 4:29 am
Astronomical Twilight end: 8:29 pm
Length of Visible Light: 1:56 pm
Length of Day: 1:06 pm
Diff Visable Light from Yesterday: -2 mins
Diff Length of day from Yesterday: -3 mins`
Code:
<?php
// set elsewhere
# or use on style "US/Phoenix" "US/Eastern" "US/Pacific"...
$SITE['TZ'] = "America/Phoenix";
$SITE['LAT'] = 33.4026;
$SITE['LONG'] = -111.8831;
get_times();
echo "<h3>24 Hour Mode</h3>\n";
echo "<b>Today:</b>
\n";
echo "Sunrise: " . $VALS['sunrise'] . "
\n";
echo "Sunset: " . $VALS['sunset'] . "
\n";
echo "Civilian Twilight start: " . $VALS['civiltwstart'] . "
\n";
echo "Civilian Twilight end: " . $VALS['civiltwend'] . "
\n";
echo "Nautical Twilight start: " . $VALS['nauticaltwstart'] . "
\n";
echo "Nautical Twilight end: " . $VALS['nauticaltwend'] . "
\n";
echo "Astronomical Twilight start: " . $VALS['astrotwstart'] . "
\n";
echo "Astronomical Twilight end: " . $VALS['astrotwend'] . "
\n";
echo "Length of Visible Light: " . $VALS['lenvislight'] . "
\n";
echo "Length of Day: " . $VALS['lenofday'] . "
\n";
echo "
\n<b>Tommorrow:</b>
\n";
echo "Sunrise: " . $VALS['tsunrise'] . "
\n";
echo "Sunset: " . $VALS['tsunset'] . "
\n";
echo "Civilian Twilight start: " . $VALS['tciviltwstart'] . "
\n";
echo "Civilian Twilight end: " . $VALS['tciviltwend'] . "
\n";
echo "Nautical Twilight start: " . $VALS['tnauticaltwstart'] . "
\n";
echo "Nautical Twilight end: " . $VALS['tnauticaltwend'] . "
\n";
echo "Astronomical Twilight start: " . $VALS['tastrotwstart'] . "
\n";
echo "Astronomical Twilight end: " . $VALS['tastrotwend'] . "
\n";
echo "Length of Visible Light: " . $VALS['tlenvislight'] . "
\n";
echo "Length of Day: " . $VALS['tlenofday'] . "
\n";
echo "
\n";
echo "Diff Visable Light from Yesterday: " .
out_time((getTimestamp($VALS['tlenvislight']) - getTimestamp($VALS['lenvislight'])),0) .
"
\n";
echo "Diff Length of day from Yesterday: " .
out_time((getTimestamp($VALS['tlenofday']) - getTimestamp($VALS['lenofday'])),0) .
"
\n";
echo "<hr><h3>12 hour Mode</h3>\n";
echo "<b>Today:</b>
\n";
echo "Sunrise: " . time24to12($VALS['sunrise']) . "
\n";
echo "Sunset: " . time24to12($VALS['sunset']) . "
\n";
echo "Civilian Twilight start: " . time24to12($VALS['civiltwstart']) . "
\n";
echo "Civilian Twilight end: " . time24to12($VALS['civiltwend']) . "
\n";
echo "Nautical Twilight start: " . time24to12($VALS['nauticaltwstart']) . "
\n";
echo "Nautical Twilight end: " . time24to12($VALS['nauticaltwend']) . "
\n";
echo "Astronomical Twilight start: " . time24to12($VALS['astrotwstart']) . "
\n";
echo "Astronomical Twilight end: " . time24to12($VALS['astrotwend']) . "
\n";
echo "Length of Visible Light: " . time24to12($VALS['lenvislight']) . "
\n";
echo "Length of Day: " . time24to12($VALS['lenofday']) . "
\n";
echo "
\n<b>Tommorrow:</b>
\n";
echo "Sunrise: " . time24to12($VALS['tsunrise']) . "
\n";
echo "Sunset: " . time24to12($VALS['tsunset']) . "
\n";
echo "Civilian Twilight start: " . time24to12($VALS['tciviltwstart']) . "
\n";
echo "Civilian Twilight end: " . time24to12($VALS['tciviltwend']) . "
\n";
echo "Nautical Twilight start: " . time24to12($VALS['tnauticaltwstart']) . "
\n";
echo "Nautical Twilight end: " . time24to12($VALS['tnauticaltwend']) . "
\n";
echo "Astronomical Twilight start: " . time24to12($VALS['tastrotwstart']) . "
\n";
echo "Astronomical Twilight end: " . time24to12($VALS['tastrotwend']) . "
\n";
echo "Length of Visible Light: " . time24to12($VALS['tlenvislight']) . "
\n";
echo "Length of Day: " . time24to12($VALS['tlenofday']) . "
\n";
echo "
\n";
echo "Diff Visable Light from Yesterday: " .
out_time((getTimestamp($VALS['tlenvislight']) - getTimestamp($VALS['lenvislight'])),0) .
"
\n";
echo "Diff Length of day from Yesterday: " .
out_time((getTimestamp($VALS['tlenofday']) - getTimestamp($VALS['lenofday'])),0) .
"
\n";
exit;
function get_times() {
global $SITE, $VALS;
// Set the timezone we want to use
set_tz( $SITE['TZ'] );
// Use your location information
$lat = $SITE['LAT']; // South is negative
$long = $SITE['LONG']; // West is negative
$timeused = $timetoday;
$timetoday = time();
$timetommorrow = $timetoday + 86400;
$zenith=90+50/60;
$VALS['sunrise'] = date_sunrise($timetoday, SUNFUNCS_RET_STRING, $lat, $long, $zenith);
$VALS['sunset'] = date_sunset($timetoday, SUNFUNCS_RET_STRING, $lat, $long, $zenith);
$VALS['tsunrise'] = date_sunrise($timetommorrow, SUNFUNCS_RET_STRING, $lat, $long, $zenith);
$VALS['tsunset'] = date_sunset($timetommorrow, SUNFUNCS_RET_STRING, $lat, $long, $zenith);
$zenith=96;
$VALS['civiltwstart'] = date_sunrise($timetoday, SUNFUNCS_RET_STRING, $lat, $long, $zenith);
$VALS['civiltwend'] = date_sunset($timetoday, SUNFUNCS_RET_STRING, $lat, $long, $zenith);
$VALS['tciviltwstart'] = date_sunrise($timetommorrow, SUNFUNCS_RET_STRING, $lat, $long, $zenith);
$VALS['tciviltwend'] = date_sunset($timetommorrow, SUNFUNCS_RET_STRING, $lat, $long, $zenith);
$zenith=102;
$VALS['nauticaltwstart'] = date_sunrise($timetoday, SUNFUNCS_RET_STRING, $lat, $long, $zenith);
$VALS['nauticaltwend'] = date_sunset($timetoday, SUNFUNCS_RET_STRING, $lat, $long, $zenith);
$VALS['tnauticaltwstart'] = date_sunrise($timetommorrow, SUNFUNCS_RET_STRING, $lat, $long, $zenith);
$VALS['tnauticaltwend'] = date_sunset($timetommorrow, SUNFUNCS_RET_STRING, $lat, $long, $zenith);
$zenith=108;
$VALS['astrotwstart'] = date_sunrise($timetoday, SUNFUNCS_RET_STRING, $lat, $long, $zenith);
$VALS['astrotwend'] = date_sunset($timetoday, SUNFUNCS_RET_STRING, $lat, $long, $zenith);
$VALS['tastrotwstart'] = date_sunrise($timetommorrow, SUNFUNCS_RET_STRING, $lat, $long, $zenith);
$VALS['tastrotwend'] = date_sunset($timetommorrow, SUNFUNCS_RET_STRING, $lat, $long, $zenith);
// Other values
$VALS['lenvislight'] = out_time((getTimestamp($VALS['civiltwend']) - getTimestamp($VALS['civiltwstart'])),1);
$VALS['lenofday'] = out_time((getTimestamp($VALS['sunset']) - getTimestamp($VALS['sunrise'])),1);
$VALS['tlenvislight'] = out_time((getTimestamp($VALS['tciviltwend']) - getTimestamp($VALS['tciviltwstart'])),1);
$VALS['tlenofday'] = out_time((getTimestamp($VALS['tsunset']) - getTimestamp($VALS['tsunrise'])),1);
}
function set_tz ($TZ){
if (phpversion() >= "5.1.0") {
date_default_timezone_set($TZ);
} else {
putenv("TZ=" . $TZ);
}
}
function getTimestamp ($val) {
list ($hour,$min) = preg_split("/:/",$val);
$ttl = ($min * 60) + ($hour * 60 * 60);
return($ttl);
}
function out_time ( $seconds , $mode = false) {
$uday = (3600 * 24);
$uhr = 3600;
$umin = 60;
if ($seconds < 0 ) {
$neg = "-" ;
$seconds = $seconds * -1 ;
//echo "Seconds = " . $seconds . "
";
} else {
$neg = "" ;
}
// Calculate days
$dd = intval($seconds / $uday );
$mmremain = ($seconds - ($dd * $uday));
// Calculate hours
$hh = intval($mmremain / $uhr);
$ssremain = ($mmremain - ($hh * $uhr));
// Calculate minutes
$mm = intval($ssremain / $umin);
$ss = ($ssremain - ($mm * $umin));
// If day or days
if ($dd == 1) { $days = 'day'; }
if ($dd > 1 ) { $days = "days"; }
if (!$mode) {
// String for if there are days
if ( $dd > 0 ) {
$out_string = sprintf("%d %s %02d hrs %02d mins",
$dd, $days, $hh, $mm);
}
// String if there are hours
if ( $dd == 0 && $hh > 0 ) {
$out_string = $neg . sprintf("%d hrs %02d mins",
$hh, $mm);
}
// String if there are minutes
if ( $dd == 0 && $hh == 0 && $mm > 0 ) {
$out_string = $neg . sprintf("%d mins",
$mm);
}
// Only output Seconds
if ( $hh == 0 && $mm == 0 ) {
$out_string = $neg . sprintf("%d secs", $ss) ;
}
} else {
// String for if there are days
if ( $dd > 0 ) {
$out_string = $neg . sprintf("%d:%s %02d:%02d",
$dd, $days, $hh, $mm);
}
// String if there are hours
if ( $dd == 0 && $hh > 0 ) {
$out_string = $neg . sprintf("%d:%02d",
$hh, $mm);
}
// String if there are minutes
if ( $dd == 0 && $hh == 0 && $mm > 0 ) {
$out_string = $neg . sprintf("00:%02d",
$mm);
}
// Only output Seconds
if ( $hh == 0 && $mm == 0 ) {
$out_string = $neg . sprintf("%d secs", $ss) ;
}
}
// Return value
return ($out_string);
}
function time24to12 ($val) {
if (strlen($val) == 5 ) {
$val .= ":00";
}
return( date("g:i a", strtotime($val)) );
}