开发者

Why does Perl's DateTime::Astro::Sunrise give me unexpected values?

Using the example code included in the man page for DateTime::Astro::Sunrise, I'm getting back ~14:00 for the sunrise and ~2:00 for the sunset.

My machine's time and timezone are set correctly (AFAIK).

Am I reading something wrong? 2am and 2pm are just so brutually wrong.

use DateTime;
use DateTime::Astro::Sunrise;

my $dt = DateTime->new( year   => 2010,
                                month  => 3,
                                day    => 15,
                         );
my $sunrise = DateTime::Astro::Sunrise ->new('-117','33',undef,1);

my ($tmp_rise, $tmp_set) = $sunrise->sunrise($dt);

printf "%s\n", $tmp_rise;
printf "%s\n", $tmp_set;
开发者_Go百科


At a guess, you've got the wrong sign on your longitude, so you're getting the sunrise/sunset times for Shanghai (which are about 6AM and 6PM Shanghai time right now), but you're getting the times in California time that the sun rises and sets in Shanghai, since that's your local timezone. Difference is 16 hours, so you get 2PM and 2AM.


Sorry, without any sample code, I can't say what you are doing wrong.

An alternative, Astro::Sunrise has been working well for me, and appears to be slightly more mature.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜