[AstroPy] Time custom formats

Varun Bhalerao varunb at iucaa.in
Mon Feb 22 00:16:24 EST 2016


An alternate way to do this:

import astropy.time
import astropy.units as u
t = astropy.time.Time.now()
tnew = t - 1*u.d
print tnew.isot

Not a full solution, but does what you need.

-- Varun
____________________
-  Varun Bhalerao  -
Office: A 214, IUCAA
Ph: +91 20 2560 4214
www.iucaa.in/~varunb



> On 20-Feb-2016, at 5:30 pm, astropy-request at scipy.org wrote:
> 
> Send AstroPy mailing list submissions to
> 	astropy at scipy.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> 	https://mail.scipy.org/mailman/listinfo/astropy
> or, via email, send a message with subject or body 'help' to
> 	astropy-request at scipy.org
> 
> You can reach the person managing the list at
> 	astropy-owner at scipy.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of AstroPy digest..."
> 
> 
> Today's Topics:
> 
>   1. Time custom formats (Paul Ray)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Fri, 19 Feb 2016 08:51:46 -0500
> From: Paul Ray <paul.ray at nrl.navy.mil>
> To: astropy at scipy.org
> Subject: [AstroPy] Time custom formats
> Message-ID: <699E05F6-DE20-4D9E-92D9-54C7B6BE6F0E at nrl.navy.mil>
> Content-Type: text/plain; charset=us-ascii
> 
> Hi,
> 
> 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
> 
> 
> 
> 
> ------------------------------
> 
> Subject: Digest Footer
> 
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> https://mail.scipy.org/mailman/listinfo/astropy
> 
> 
> ------------------------------
> 
> End of AstroPy Digest, Vol 113, Issue 11
> ****************************************




More information about the AstroPy mailing list