开发者

Sunrise time tomorrow in PHP. How?

This is my script that calculates sunrise time for San Jose for today but if I wanted to get it for tomorrow how can I do it?

<?php

//San Jose, CA
$lat = 37.339386;    // North
$long = -121.894955;    // East
$offset = -8;    // diff开发者_StackOverflow中文版erence between GMT and local time in hours

$zenith=90+50/60;
echo "<br><p>Sunrise: ".date_sunrise(time(), SUNFUNCS_RET_STRING, $lat, $long, $zenith, $offset);
echo "<br>Sunset: ".date_sunset(time(), SUNFUNCS_RET_STRING, $lat, $long, $zenith, $offset);
?>


The PHP function, time() gives you the current time in seconds since "The Epoch". You can use strtotime() to do lots of different conversions, including relative conversions.

You can use strtotime() to get the time 1-day from now:

strtotime("+1 day");

just replace time() in your code, with strtotime("+1 day")


Pass date_sunrise() and date_sunset() the parameter:

time() + (24 * 60 * 60)

For a date 24 hours in the future (ie, tomorrow).


Just add one day to your calls to the time() function. If I remember correctly, it takes seconds. So to add a day you'll need to add 60 * 60 * 24 to it.


You would need to use the date math functions to add 24 hours to time(). In place of time(), use:

strtotime('+1 day', time());


The Linux/GNU Bash command timewarp executes a given program in a timewarp thread. This mechanism uses special hardware built into most modern CPUs. The timewarp thread is isolated in a specified time, run, and returns the result now.

Here's the syntax:

timewarp --time 86400 "php calculatesunrise.php"

For more information on timework, man timewarp

This basically executes your calculation tomorrow, eliminating the need to change the algorithm. Use exec() to run this. Note, this does not work on a Windows machine. If you need it to work on a Windows machine, use sleep(86400) instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜