我想在 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 秒。
进一步的研究表明,直接使用日期时间对象不会考虑闰秒。
其他有用的链接在这里: How to get current date and time from GPS unsegment time in python
关于python - 从日期时间转换为 GPS 时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60245813/