Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

how to convert a timestamp to MJD (Modified Julian Date)

by tmacy (Initiate)
on Sep 23, 2007 at 23:13 UTC ( #640626=perlquestion: print w/ replies, xml ) Need Help??
tmacy has asked for the wisdom of the Perl Monks concerning the following question:

Looking to convert timestamps (time in seconds as returned by mktime) to a Modified Julian Dates. I have been using DateTime::Format::Epoch::MJD to convert Julian to Gregorian but that does not appear to me, at least, to work for going the other way. I have attempted various Google searches and found plenty or information about converting Mod Julian to Gregorian but little for going the other direction.

Comment on how to convert a timestamp to MJD (Modified Julian Date)
Re: how to convert a timestamp to MJD (Modified Julian Date)
by Joost (Canon) on Sep 23, 2007 at 23:25 UTC
Re: how to convert a timestamp to MJD (Modified Julian Date)
by talexb (Canon) on Sep 24, 2007 at 00:56 UTC

    In case you didn't get the hint, it's strongly recommended that you search for what you're looking for, before posting a node asking a question.

    We're much more likely to help when a query describes the problem, and which searches have come up dry -- or advice on which approach (as the result of your search) might be the best (for some definition of 'best').

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Re: how to convert a timestamp to MJD (Modified Julian Date)
by apl (Monsignor) on Sep 24, 2007 at 10:01 UTC
    In addition to what talexb said, it'd help if you defined what timestamp means to you. I have three users who'd define it three different ways...
Re: how to convert a timestamp to MJD (Modified Julian Date)
by Anonymous Monk on Sep 25, 2007 at 19:49 UTC
    Yes, it would have been better to be more specific with the question, including an example. But that does not excuse the rudeness of the replies. Obviously the module was located, but upon casually reviewing the inadequate documentation, I would have the same question.
      now that I'm logged in, I will claim this comment as mine!
        Now that you're logged in, I'll reply here so you'll get a notification of my reply :-)

        that does not excuse the rudeness of the replies. Obviously the module was located, but upon casually reviewing the inadequate documentation, I would have the same question.

        1. I wasn't being rude, I posted a link to an obvious first module to try when solving the problem.

        2. It wasn't at all obvious the module was located - that information was added later. If the original poster already tried the module and/or couldn't get it to do what he wanted he should have said so, preferably with some specific pointers/questions about why it didn't work.

        See also How do I post a question effectively?

        Update: removed some irrelevant stuff when I saw the OP was edited.

Re: how to convert a timestamp to MJD (Modified Julian Date)
by Joost (Canon) on Sep 25, 2007 at 20:43 UTC
    It's common practice on this site to make any significant edits to your node clear (for instance, by starting new paragraphs with "update:" or striking out outdated lines. That way you won't make the people who replied to the first version of the post look like idiots :-)

    Anyway, since you seem to want to convert standard Unix time - seconds since 0:00 1/1/1970 - to MJD - fractional number of days since 0:00 November 17, 1858 - correct me if I'm wrong here - try this:

    #!/usr/bin/perl -w use strict; use DateTime::Format::Epoch::MJD; use DateTime::Format::Epoch::Unix; print DateTime::Format::Epoch::MJD->format_datetime( DateTime::Format: +:Epoch::Unix->parse_datetime( time ) );
    Note that the time function returns the current unix date on all systems I know of except Mac OS classic.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://640626]
Approved by Joost
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-07-25 04:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (167 votes), past polls