<tfoot id='Xdg6b'></tfoot>
<legend id='Xdg6b'><style id='Xdg6b'><dir id='Xdg6b'><q id='Xdg6b'></q></dir></style></legend>
    <bdo id='Xdg6b'></bdo><ul id='Xdg6b'></ul>

<small id='Xdg6b'></small><noframes id='Xdg6b'>

    1. <i id='Xdg6b'><tr id='Xdg6b'><dt id='Xdg6b'><q id='Xdg6b'><span id='Xdg6b'><b id='Xdg6b'><form id='Xdg6b'><ins id='Xdg6b'></ins><ul id='Xdg6b'></ul><sub id='Xdg6b'></sub></form><legend id='Xdg6b'></legend><bdo id='Xdg6b'><pre id='Xdg6b'><center id='Xdg6b'></center></pre></bdo></b><th id='Xdg6b'></th></span></q></dt></tr></i><div id='Xdg6b'><tfoot id='Xdg6b'></tfoot><dl id='Xdg6b'><fieldset id='Xdg6b'></fieldset></dl></div>

        如何从python中的GPS取消分段时间获取当前日期和时间

        How to get current date and time from GPS unsegment time in python(如何从python中的GPS取消分段时间获取当前日期和时间)
      1. <tfoot id='22b7L'></tfoot>

        <small id='22b7L'></small><noframes id='22b7L'>

        • <bdo id='22b7L'></bdo><ul id='22b7L'></ul>
            <i id='22b7L'><tr id='22b7L'><dt id='22b7L'><q id='22b7L'><span id='22b7L'><b id='22b7L'><form id='22b7L'><ins id='22b7L'></ins><ul id='22b7L'></ul><sub id='22b7L'></sub></form><legend id='22b7L'></legend><bdo id='22b7L'><pre id='22b7L'><center id='22b7L'></center></pre></bdo></b><th id='22b7L'></th></span></q></dt></tr></i><div id='22b7L'><tfoot id='22b7L'></tfoot><dl id='22b7L'><fieldset id='22b7L'></fieldset></dl></div>
                  <tbody id='22b7L'></tbody>

                  <legend id='22b7L'><style id='22b7L'><dir id='22b7L'><q id='22b7L'></q></dir></style></legend>

                  本文介绍了如何从python中的GPS取消分段时间获取当前日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有这样的 GPS 未分段时间:

                  I have gps unsegmented time like this:

                  Tgps = 1092121243.0
                  

                  我想知道那是什么日期和时间.GPS时间的开始日期是1980年1月6日.Python函数

                  And I'd like to understand what date and time is that. The begining of GPS time is 6 January 1980. Python function

                  datetime.utcfromtimestamp 
                  

                  可以给出从 1970 年 1 月 1 日开始的秒数.

                  could give seconds from 1 January 1970 year.

                  我发现了以下内容:

                  from datetime import datetime
                  GPSfromUTC = (datetime(1980,1,6) - datetime(1970,1,1)).total_seconds()
                  curDate = datetime.utcfromtimestamp(Tgps + GPSfromUTC) 
                  
                  Out[83]: datetime.datetime(2014, 8, 15, 7, 0, 43)
                  

                  我不确定闰秒是否包含在函数 datetime 中,或者我应该计算它们并从结果中减去?是否也存在更好的解决这个问题的方法?

                  I'm not sure about leapseconds are they included in function datetime or I should calculate them and substract from the result? May be also exists better solution of this problem?

                  推荐答案

                  GPS 时间开始与 UTC 同步:1980-01-06 (UTC) == 1980-01-06 (GPS).两者都以 SI 秒为单位.GPS 时间和 UTC 时间之间的差异会随着每个(闰)闰秒而增加.

                  GPS time started in sync with UTC: 1980-01-06 (UTC) == 1980-01-06 (GPS). Both tick in SI seconds. The difference between GPS time and UTC time increases with each (intercalary) leap second.

                  要找到正确的 UTC 时间,您需要知道在给定 GPS 时间之前发生的闰秒数:

                  To find the correct UTC time, you need to know the number of leap seconds occurred before the given GPS time:

                  #!/usr/bin/env python
                  from datetime import datetime, timedelta
                  
                  # utc = 1980-01-06UTC + (gps - (leap_count(2014) - leap_count(1980)))
                  utc = datetime(1980, 1, 6) + timedelta(seconds=1092121243.0 - (35 - 19))
                  print(utc)
                  

                  输出

                  2014-08-15 07:00:27 # (UTC)
                  

                  其中 leap_count(date) 是在给定日期之前引入的闰秒数.来自 TAI-UTC 表(注意: 该网站是闰秒的权威来源.它发布 Bulletin C 宣布新闰秒):

                  where leap_count(date) is the number of leap seconds introduced before the given date. From TAI-UTC table (note: the site is the authoritative source on leap seconds. It publishes Bulletin C announcing new leap seconds):

                  1980..: 19s 
                  2012..: 35s
                  

                  因此:

                  (leap_count(2014) - leap_count(1980)) == (35 - 19)
                  

                  <小时>

                  如果您使用的是 Unix,那么您可以使用 "right" 时区从 TAI 时间获取 UTC 时间(并且很容易从 GPS 时间得到 TAI 时间:TAI = GPS + 19 秒(恒定偏移)):


                  If you are on Unix then you could use "right" time zone to get UTC time from TAI time (and it is easy to get TAI time from GPS time: TAI = GPS + 19 seconds (constant offset)):

                  #!/usr/bin/env python
                  import os
                  import time
                  
                  os.environ['TZ'] = 'right/UTC' # TAI scale with 1970-01-01 00:00:10 (TAI) epoch
                  time.tzset() # Unix
                  
                  from datetime import datetime, timedelta
                  
                  gps_timestamp = 1092121243.0 # input
                  gps_epoch_as_gps = datetime(1980, 1, 6) 
                  # by definition
                  gps_time_as_gps = gps_epoch_as_gps + timedelta(seconds=gps_timestamp) 
                  gps_time_as_tai = gps_time_as_gps + timedelta(seconds=19) # constant offset
                  tai_epoch_as_tai = datetime(1970, 1, 1, 0, 0, 10)
                  # by definition
                  tai_timestamp = (gps_time_as_tai - tai_epoch_as_tai).total_seconds() 
                  print(datetime.utcfromtimestamp(tai_timestamp)) # "right" timezone is in effect!
                  

                  输出

                  2014-08-15 07:00:27 # (UTC)
                  

                  <小时>

                  如果您从相应的 tzfile(5).它是前两种方法的组合,其中第一种方法的跳跃计数计算是自动的,并且自动更新 tzdata(tz 数据库) 来自第二种方法:


                  You could avoid changing the timezone if you extract the leap seconds list from the corresponding tzfile(5). It is a combination of the first two methods where the leap count computation from the first method is automated and the autoupdating tzdata (system package for the tz database) from the second method is used:

                  >>> from datetime import datetime, timedelta
                  >>> import leapseconds
                  >>> leapseconds.gps_to_utc(datetime(1980,1,6) + timedelta(seconds=1092121243.0))
                  datetime.datetime(2014, 8, 15, 7, 0, 27)
                  

                  leapseconds.py可以从/usr/share/zoneinfo/right/UTC 文件(tzdata 包的一部分).

                  where leapseconds.py can extract leap seconds from /usr/share/zoneinfo/right/UTC file (part of tzdata package).

                  所有三种方法产生相同的结果.

                  All three methods produce the same result.

                  这篇关于如何从python中的GPS取消分段时间获取当前日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)

                1. <small id='zkd5h'></small><noframes id='zkd5h'>

                      <tbody id='zkd5h'></tbody>

                  • <i id='zkd5h'><tr id='zkd5h'><dt id='zkd5h'><q id='zkd5h'><span id='zkd5h'><b id='zkd5h'><form id='zkd5h'><ins id='zkd5h'></ins><ul id='zkd5h'></ul><sub id='zkd5h'></sub></form><legend id='zkd5h'></legend><bdo id='zkd5h'><pre id='zkd5h'><center id='zkd5h'></center></pre></bdo></b><th id='zkd5h'></th></span></q></dt></tr></i><div id='zkd5h'><tfoot id='zkd5h'></tfoot><dl id='zkd5h'><fieldset id='zkd5h'></fieldset></dl></div>

                    <legend id='zkd5h'><style id='zkd5h'><dir id='zkd5h'><q id='zkd5h'></q></dir></style></legend>

                          <bdo id='zkd5h'></bdo><ul id='zkd5h'></ul>
                          <tfoot id='zkd5h'></tfoot>