1

Given a UTC timestamp (e.g. the string '2006-03-01 11:18:15.500000+11:00'), how should I convert it to a Time object in skyfield (successor of pyEphem)?

For example, can skyfield use standard python datetime objects?

benjimin
  • 4,043
  • 29
  • 48

1 Answers1

2
>>> import dateutil.parser, skyfield.api
>>> ts = skyfield.api.load.timescale()
>>> t = ts.utc(dateutil.parser.parse('2006-03-01 11:18:15.500000+11:00'))
>>> t.utc_datetime() # just to confirm
datetime.datetime(2006, 3, 1, 0, 18, 15, 500000, tzinfo=<UTC>)

Notice that skyfield.api.Timescale.utc can take a single datetime object for input, instead of a sequence of components (so don't be confused by its call signature in the docs).

benjimin
  • 4,043
  • 29
  • 48