[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Time convertion

Alex Schuster wrote:
> Hi!
> I have to convert some date formats, and I wonder why IDL does not give
> more support here. A common date/time format is the seconds since 1970,
> and the systime() funtion can return the current date in this format.
> Yippie! But why is there no function to convert this from/to standard
> ASCII date strings, or from/to Julian date?
> I found such a thing in the Astro library, st2date, input is the
> seconds-since-1970, output is year, month, day etc., and even day and
> month in ASCII notation if one likes. Great. But I did not find
> something yet to convert to seconds-since-1970. I could write it myself,
> but I guess this already had be done some dozen times. Some big routine
> with many, many keywords to convert between all those formats would be
> nice :)

Hmm... I doubt you found that in the Astro library, since I wrote it and
posted it to the newsgroup back in 1998.  I did use daycnv from the
astro package to convert julian to calendar dates.  The recent
IDL-bundled "caldat" will work just as well for that now.  In any case,
it is oh so trivial to convert date to systime, the inverse:


That's it!  For instance:

IDL> st0=systime(0) & st1=systime(1)
IDL> d=bin_date(st0)
IDL> st=(julday(d[1],d[2],d[0],d[3],d[4],d[5])-2440587.5D)*86400.0D 
IDL> print,FORMAT='(A,":",2D30.5)',st0,st1,st

Keeping in mind that systime(1) often returns GMT on many systems,
whereas systime(0) returns localtime, meaning you might have several
hours offset between st1 and st above.  For me, st1-st=5 hours (EST).

Good luck,