How to convert skyfield Time into datetime at specific timezone
When you have a skyfield Time
object like
t = ts.now()
# Example: <Time tt=2459750.027604357>
you can convert it to a Python datetime
in a specific timezone (Europe/Berlin
in this example) using .astimezone()
and the pytz
library:
t.astimezone(pytz.timezone("Europe/Berlin"))
# Example: datetime.datetime(2022, 6, 19, 14, 38, 35, 832445, tzinfo=<DstTzInfo 'Europe/Berlin' CEST+2:00:00 DST>)
Complete example
from skyfield import api
from datetime import datetime
import pytz
ts = api.load.timescale()
t = ts.now()
dt = t.astimezone(pytz.timezone("Europe/Berlin"))
print(dt) # e.g. 2022-06-19 14:42:47.406786+02:00