[AstroPy] Time custom formats

Paul Ray paul.ray at nrl.navy.mil
Fri Feb 19 08:51:46 EST 2016


I've been trying to figure out how to print an astropy.Time with a custom string format and have not been able to.

In [2]: t = astropy.time.Time.now()

In [3]: t.yday
Out[3]: '2016:050:13:45:21.260'

Now, what if I want the string '2016-050T13:45:21' instead?
What I'd like is basically the astropy equivalent of the C library strftime().

I see there is a way to make a new subclass of TimeFormat, but I don't really want a whole new format, just a way to customize the string representation (possibly for input as well as output).  Maybe all I need is an example of how to subclass TimeFormat to accomplish that. I had some trouble getting it to work in the little experimenting I did.

Thanks for any tips,

-- Paul

More information about the AstroPy mailing list