Re: HELP with systime() [message #10877] |
Wed, 11 February 1998 00:00 |
safier
Messages: 12 Registered: March 1995
|
Junior Member |
|
|
>>>> > "Mark" == Mark Elliott <mark@mail.mmrrcc.upenn.edu> writes:
Mark> Is there a way to convert a binary time value like the one
Mark> returned by
Mark> timeval = systime(1)
Mark> into a date string like
Mark> DOW MON DD HH:MM:SS YEAR ?
Mark> I've found bin_date() but it accepts only the
Mark> ascii_time format for input. I'd like to convert the number
Mark> of seconds since 1/1/1970 into the month,day,year,... that
Mark> it corresponds to.
If you are on a unix system, you can use spawn and the Unix date
command:
spawn('date',mydate)
The output of date will be in mydate.
Hope this helps...
Pedro
--
Pedro N. Safier | "God offers to everyone his
Department of Astronomy | choice between truth and repose.
U. of Maryland at College Park | Take which you please--you can
phone: 301-405-1531; fax: 301-314-9067 | never have both." R. W. Emerson
|
|
|
Re: HELP with systime() [message #10881 is a reply to message #10877] |
Wed, 11 February 1998 00:00  |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
Mark Elliott <mark@mail.mmrrcc.upenn.edu> writes:
> Is there a way to convert a binary time value like the one
> returned by
> timeval = systime(1)
> into a date string like
> DOW MON DD HH:MM:SS YEAR ?
> I've found bin_date() but it accepts only the ascii_time format
> for input. I'd like to convert the number of seconds since 1/1/1970 into
> the month,day,year,... that it corresponds to.
There are a number of time conversion routines available from
ftp://sohoftp.nascom.nasa.gov/solarsoft/gen/idl/time/
For example, the routine sec2utc can convert a time in seconds (ignoring leap
seconds) to calculate the Modified Julian Day (MJD) number, and the number of
milliseconds into the day. For example,
sec = systime(1)+40587.d0*86400.d0
utc = sec2utc(sec)
(40587 is the MJD of 1-Jan-1970, and 86400 is the number of seconds in a day.)
The routine anytim2utc can then be used to convert this into a number of
different formats. For example,
IDL> print,utc
{ 50855 82039210}
IDL> print, anytim2utc(utc,/ccsds)
1998-02-11T22:47:19.210Z
IDL> print, anytim2utc(utc,/vms)
11-Feb-1998 22:47:19.210
IDL> help, /structure, anytim2utc(utc,/ext)
** Structure CDS_EXT_TIME, 7 tags, length=14:
YEAR INT 1998
MONTH INT 2
DAY INT 11
HOUR INT 22
MINUTE INT 47
SECOND INT 19
MILLISECOND INT 210
The routine utc2dow calculates the day-of-week. For example,
IDL> dow = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
IDL> print, dow(utc2dow(utc))
Wed
There are also facilities for converting UTC time into TAI time, and
vice-versa, with leap-seconds fully accounted for.
Bill Thompson
|
|
|
Re: HELP with systime() [message #10886 is a reply to message #10877] |
Wed, 11 February 1998 00:00  |
Liam Gumley
Messages: 473 Registered: November 1994
|
Senior Member |
|
|
Mark Elliott wrote:
>
> Is there a way to convert a binary time value like the one
> returned by
>
> timeval = systime(1)
>
> into a date string like
>
> DOW MON DD HH:MM:SS YEAR ?
>
> I've found bin_date() but it accepts only the ascii_time format
> for input. I'd like to convert the number of seconds since 1/1/1970 into
> the month,day,year,... that it corresponds to.
http://fermi.jhuapl.edu/s1r/idl/s1rlib/time/time.html
is very useful and informative for this purpose.
Cheers,
Liam.
|
|
|
Re: HELP with systime() [message #10887 is a reply to message #10877] |
Wed, 11 February 1998 00:00  |
Brian Jackel
Messages: 34 Registered: January 1998
|
Member |
|
|
Mark Elliott asked:
> Is there a way to convert a binary time value like the one
> returned by
>
> timeval = systime(1)
>
> into a date string like
>
> DOW MON DD HH:MM:SS YEAR ?
>
> I've found bin_date() but it accepts only the ascii_time format
> for input. I'd like to convert the number of seconds since 1/1/1970
> into the month,day,year,... that it corresponds to.
>
A couple years ago I wrote some code to do what you're asking
about. However, I recently discovered an easier way of doing
things, using the CDF_EPOCH function, which is part of the
Common Data Format library included with IDL. It can do two
things
1) Given a year,month,day etc. return the time in milliseconds
since a reference time (0 AD). Use this to find out when
the standard Unix reference time started:
CDF_EPOCH,UnixEpoch,1970,1,1,0,0,0,/COMPUTE_EPOCH
2) Turn a reference time back into year, month, day etc.
Add the number of milliseconds given by SYSTIME to
the Unix reference time
CurrentEpoch= UnixEpoch + SYSTIME(1) * 1000.0d0
Then recover the information you want
CDF_EPOCH,CurrentEpoch,year,month,day,hour,minute,second, $
/BREAKDOWN_EPOCH
which you can format as needed. Hope this helps. Oh,
there's one little problem. The CDF stuff works in
Universal Time, while SYSTIME tends to correct for the
current time zone. Be careful...
Brian Jackel
|
|
|
Re: HELP with systime() [message #10888 is a reply to message #10877] |
Wed, 11 February 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Mark Elliott (mark@mail.mmrrcc.upenn.edu) writes:
> Is there a way to convert a binary time value like the one
> returned by
>
> timeval = systime(1)
>
> into a date string like
>
> DOW MON DD HH:MM:SS YEAR ?
>
How about:
Print, SysTime()
If you have your own binary date (say, Julian date), you
can convert it with CalDat.
Cheers,
David
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|