in reply to getting a utc value from julian date
I'd be happy with creating a DateTime object from julian, but I don't see that as one of the options (one can go the other direction).I tried something like
and came out withmy $dt = DateTime->today; say $dt, " = ", $dt->jd; $dt->subtract(days => $dt->jd, hours => 12); # days implicitly truncat +ed to int say $dt, " = ", $dt->jd;
So,2015-06-29T00:00:00 = 2457202.5 -4713-11-24T12:00:00 = 0
givesmy $jd_to_convert = 2457205.09613609; my $dt = DateTime->new(year => -4713, month => 11, day =>24, hour => 1 +2)->add(days => $jd_to_convert); say $dt, " = ", $dt->jd;
(With Time::Piece the method would be the same)2015-07-01T12:00:00 = 2457205
Now you just need to convert the fractional part to h m s...
Update: Hah! DateTime accepts fractional hours, exactitude about 0.15 sec on my system[further update: added comments and time zone, as JD is relative to UTC]sub jd2dt { # convert JD to DateTime my $jd_to_convert = shift; my $days = int $jd_to_convert; # that odd date is "julian day zero", converted to "proleptic" gre +gorian calendar my $dt = DateTime->new(year => -4713, month => 11, day =>24, hour +=> 12, time_zone => DateTime::TimeZone->new( name => 'UTC' ))->add(da +ys => $days); $dt->add(hours => 24 * ($jd_to_convert - $days)); return $dt; # 2017-06-13 added this line for clarity }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: getting a utc value from julian date
by Aldebaran (Curate) on Jun 30, 2015 at 04:57 UTC | |
by soonix (Chancellor) on Jun 30, 2015 at 06:37 UTC |