gpt4 book ai didi

python - 从日期时间转换为 GPS 时间

转载 作者:行者123 更新时间:2023-12-04 10:34:37 28 4
gpt4 key购买 nike

我想在 python 环境中将日期时间字符串数组 (YYYY-MM-DD hh:mm:ss) 转换为 GPS 秒(2000-01-01 12:00:00 之后的秒数)。

为了在 Linux BASH 中获取单个日期的 GPS 秒数,我只需输入 date2sec datetimestring它返回一个数字。

我可以在 python 的 for 循环中执行此操作。但是,我如何将它合并到 python 脚本中,因为它是一个外部脚本?

或者,是否有另一种方法可以在不使用 date2sec 的情况下将日期时间字符串数组(或合并到 for 循环中的单个日期时间字符串)转换为 GPS 时间?

最佳答案

更新答案 :使用 Astropy 库:

from astropy.time import Time

t = Time('2019-12-03 23:55:32', format='iso', scale='utc')
print(t.gps)

在这里,您以 UTC 和 t.gps 设置日期将日期时间转换为 GPS 秒。

进一步的研究表明,直接使用 datetime 对象不会考虑闰秒。

其他有用的链接在这里:
How to get current date and time from GPS unsegment time in python

关于python - 从日期时间转换为 GPS 时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60245813/

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