Search code examples
pythonpython-2.7timeutcastropy

How to convert J2000 time to UTC in python?


I have time in J2000 format, ie. seconds after noon on 1-1-2000, which I want to convert to UTC time in an array with the format [year-month-day hour:min:sec.millisec]. Is there some function in AstroPy or something similar to do the conversion?

Input: Time in J2000: 559889620.293 seconds

Desired Output: Time in UTC: 2017-09-28 16:53:40.293


Solution

  • If you want to use astropy you could use Time and TimeDelta from astropy.time:

    >>> from astropy.time import TimeDelta, Time
    >>> from astropy import units as u
    >>> (Time(2000, format='jyear') + TimeDelta(559889620.293*u.s)).iso
    '2017-09-28 16:53:35.293'
    

    The Time(2000, format='jyear') is a good alternative if you don't want to remember what the baseline for julian dates (noon on 1.1.2000) is.