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

标签 python bash time gps gps-time

我想在 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/

相关文章:

python - Whoosh 索引查看器

linux - 如何使用 mailx 将脚本文件发送给 Linux 主机上的另一个用户

bash - 双星号 (**) 通配符是什么意思?

python - 使用python计算分数时间

java - 如何在控制台打印 "Today is May 22, 2014 and it is 2:04 pm"?

javascript - 比较 Javascript 日期与 php 当前日期

python - 如何获取多个列表并嵌套它们?

python - 使用 Python 从网上下载 csv 文件

python - Windows XP - 在 Python 中以编程方式静音/取消静音音频

linux - 如何在 bash 脚本中通过掩码更改字符串?