How to convert J2000 time to UTC in python?

Viewed 5627

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

3 Answers

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.

The offset is constant, so you can just add it:

>>> OFFSET = datetime(2000,1,1,12) - datetime(1970,1,1)
>>> datetime.utcfromtimestamp(559889620.293) + OFFSET
datetime.datetime(2017, 9, 28, 16, 53, 40, 293000)

You can simply add a timedelta to a base datetime.

import datetime
datetime.datetime(2000, 1, 1, 12, 0) + datetime.timedelta(seconds=559889620.293)

returns:

datetime.datetime(2017, 9, 28, 16, 53, 40, 293000)
Related