Skip to content

Instantly share code, notes, and snippets.

@MaxPowerWasTaken
Created January 10, 2021 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaxPowerWasTaken/689cea44ddc8911282f0fc79be08861a to your computer and use it in GitHub Desktop.
Save MaxPowerWasTaken/689cea44ddc8911282f0fc79be08861a to your computer and use it in GitHub Desktop.
from skyfield.api import EarthSatellite, load
from datetime import datetime
import math
# TLE DATA
line1 = '1 25544U 98067A 14020.93268519 .00009878 00000-0 18200-3 0 5082'
line2 = '2 25544 51.6498 109.4756 0003572 55.9686 274.8005 15.49815350868473'
# GET TIME IN UTC FROM SKYFIELD LIBRARY
ts = load.timescale()
satellite = EarthSatellite(line1, line2, 'Name Missing', ts)
t = satellite.epoch.utc
# GET WHOLE-SECONDS vs MICROSECONDS
seconds = math.floor(t.second)
fractional_seconds = t.second - math.floor(t.second)
microseconds = int(fractional_seconds * 1e6)
# CONSTRUCT DATETIME.DATETIME OBJECT
utc_time_as_datetime = datetime(year=t.year, month=t.month, day=t.day, hour=t.hour, minute=t.minute, second=seconds, microsecond=microseconds)
print(utc_time_as_datetime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment