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
my $dt = DateTime->today; say $dt, " = ", $dt->jd; $dt->subtract(days => $dt->jd, hours => 12); # days implicitly truncat +ed to int say $dt, " = ", $dt->jd;
and came out with
2015-06-29T00:00:00 = 2457202.5 -4713-11-24T12:00:00 = 0
So,
my $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;
gives
2015-07-01T12:00:00 = 2457205
(With Time::Piece the method would be the same)

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
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 }
[further update: added comments and time zone, as JD is relative to UTC]

In reply to Re: getting a utc value from julian date by soonix
in thread getting a utc value from julian date by Aldebaran

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.