Have you ever wanted to print is it night or day, or what time is sunrise or sunset?
Perhaps you want to display something on your site only during daytime or night time.
You can do this with weather display tags (and I do), but here is how using pure PHP.
Requires PHP 5 (version 5.1.3 or higher recommended, due to date_sunset bug fixes in 5.1.3)
It works on my server because my server is setup to use America/Los_Angeles timezone.
niko, can you do me a favor and put this in the top of the script, then try it and let me know:
// Set the timezone for your location, because some servers are in different timezone than your location
$myTZ = "America/Los_Angeles"; //NOTE: this *MUST* be set correctly
// translate UTC times to your LOCAL time for the displays.
putenv("TZ=$myTZ");
If it works I will edit my post and add it in. Thanks
$myTZ = 'America/New_York'; // NOTE: this *MUST* be set correctly
$time_format = 'h:i a T'; // 08:53 pm PDT
// Set the latitude and longitude for your location
$latitude = 38.36; //North
$longitude = -76.62; //West
// Set the timezone for your location, because some servers are in different timezone than your location
$myTZ = "America/Los_Angeles"; //NOTE: this *MUST* be set correctly
// translate UTC times to your LOCAL time for the displays.
putenv("TZ=$myTZ");
Looks like Mike missed it when updating the posted code.
Here is what I did but not get an error message. Did I put it in the wrong place?
// Set the timezone for your location, because some servers are in different timezone than your location
// http://saratoga-weather.org/timezone.txt has the list of timezone names
$myTZ = 'America/New_York'; // NOTE: this *MUST* be set correctly
// translate UTC times to your LOCAL time for the displays.
putenv("TZ=$myTZ");
$time_format = 'h:i a T'; // 08:53 pm PDT
// Set the latitude and longitude for your location
$latitude = 38.36; //North
$longitude = -76.62; //West
Kevin,
I see you commented the putenv(“TZ=$myTZ”);
try again after uncommenting it, because I tried with your settings and get “Sunset will occur at 07:27 pm MST”