gpt4 book ai didi

python - 将 TLE 时间(小数天数)转换为纪元后的秒数

转载 作者:太空宇宙 更新时间:2023-11-03 15:04:05 33 4
gpt4 key购买 nike

标准的两行元素 (TLE) 格式包含 2 位数年份加小数天的时间,因此 16012.375 将是 2016 年 1 月 12 日 09:00。使用 python 的 timedatatime 模块,如何将其转换为纪元后的秒数?我想我应该使用结构化时间,但我不确定如何使用。 seconds_of 是一个虚构的函数 - 需要替换为真实的东西。

编辑:如果答案很长(冗长)将是最有帮助的 - 比如每行一步左右,这样我就可以理解发生了什么。

编辑 2:在看到@J.F.Sebastian 的评论后,我查看了 TLE 的链接,发现它没有任何地方显示“UTC”。所以我应该指出初始信息和最终信息是UTC。没有引用本地时间、时区或系统时间。

例如

tim = "16012.375"

year = 2000 + int(tim[0:2])
decimal_days = float(tim[2:])

print year, decimal_days

2016, 12.375

# seconds_of is a fictitious function - need to replace with something real
seconds_after_epoch = seconds_of(2016,1,1) + (3600. * 24.) * decimal_days

最佳答案

您可以尝试这样的事情 [根据评论进行编辑]。

import datetime
import time
# get year 2 digit and floating seconds days
y_d, nbs = "16012.375".split('.')

# parse to datetime (since midnight and add the seconds) %j Day of the year as a zero-padded decimal number.
d = datetime.datetime.strptime(y_d, "%y%j") + datetime.timedelta(seconds=float("." + nbs) * 24 * 60 * 60)
# 1.0 => 1 day
# from time tuple get epoch time.
time.mktime(d.timetuple())

#1481896800.0

关于python - 将 TLE 时间(小数天数)转换为纪元后的秒数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34849083/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com