Unix 纪元和 GPS 纪元之间的刻度 [英] Ticks between Unix epoch and GPS epoch

查看:47
本文介绍了Unix 纪元和 GPS 纪元之间的刻度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Unix 时间纪元(1970 年 1 月 1 日)和 GPS 时间纪元(1980 年 1 月 6 日)之间的一秒滴答数是多少?

What is the number of one second ticks between Unix time epoch (01 Jan 1970) and GPS time epoch (06 Jan 1980)?

我在网络上的多个来源中看到了多个答案.一个阵营声称答案是315964800,另一个阵营声称答案是315964819.一直以为是315964800,现在不太确定了.

I have seen multiple answers from several sources on the web. One camp claims the answer is 315964800, the other claims it is 315964819. I always thought it was 315964800, but now am not so sure.

我刚刚发现我的软件基线在过去八年中一直在使用 315964819.当我们将嵌入式设备与其他设备集成时,我很难理解它是如何减少 19 秒的,而没有人注意到这一点.

I just found my software baseline has been using 315964819 for the last eight years. I have a hard time understanding how it could have been 19 seconds off and no one noticed it when we integrated our embedded devices with other devices.

我认为将 315964819 放入代码基线的人一定是错误地使用了 TAI 偏移量(19 秒).

I think that whoever put 315964819 in the code baseline must have mistakenly used a TAI offset (19 seconds).

据我所知,Unix 时间不包括闰秒,这表明 315964800 是两个时期之间的滴答数.然后我想了 Unix 时间是如何处理闰秒的.它只是在插入闰秒时重复滴答计数,并且在 1970 年和 1980 年之间插入了 19 个闰秒......我开始怀疑重复的滴答声是否重要.我不这么认为,但是这段代码历史上有人这么认为,而且它似乎有效......

From what I understand, Unix time does not include leap seconds, which would indicate to me that 315964800 is the number of ticks between the two epochs. Then I think about how Unix time handles the leap second. It simply repeats the tick count when there is a leap second inserted, and there were 19 leap seconds inserted between 1970 and 1980... I start to wonder if the repeated ticks matter. I do not think so, but someone in this code's history thought so, and it seemed to work....

总而言之,我将在这个产品的黑暗时代改变一个常数集,这与时间有关,这对平台很重要,从过去到我认为更多准确,而且我希望得到比我知识渊博的人的点赞.

The long and short of it is I am about to change a constant set in the dark ages of this product that has to do with timing, which is important for the platform, from what it had been to what I believe is more accurate, and I wanted some sort of thumbs-up from more knowledgeable people than me.

请有权威的人进来看看吗?

Can someone authoritative please step in here?

315964800 营

315964819 营

另请注意,我只询问 Unix 纪元到 GPS 纪元.我很确定我们已经有了闰秒,因为 GPS 时代被适当地覆盖了.

Also note that I'm only asking about Unix epoch to GPS epoch. I'm pretty sure we've got leap seconds since GPS epoch covered appropriately.

推荐答案

您所说的不同值是由于将 1970 到 1980 偏移量与闰秒混淆造成的.
正确的偏移值为 315964800 秒.

The different values you stated are caused by mixing up the 1970 to 1980 offset with leap seconds.
The correct offset value is 315964800 seconds.

说明:

UTC 和 GPS 时间(平均)每 18 个月多偏离一秒.这称为闰秒,在 UTC 时基中引入,需要根据地球自转的变化进行调整.

UTC and GPS time deviate (on average) every 18 months by one additional second. This is called a leap second, introduced in UTC time base, necessary to adjust for changes in the earth's rotation.

GPS 时间未按闰秒调整.

GPS Time not adjusted by leap seconds.

目前 (2013) 有 16 秒的偏移:
GPS 时间-UTC = 16 秒

Currently (2013) there is an offset of 16s:
GPS Time-UTC = 16 seconds

Unix 时间是一种时间格式,而不是时间参考.它表示自 1.1.1970 UTC 以来的毫秒数(或秒数).理想情况下,您的系统时间通过 TimeServer (NTP) 与 UTC 同步.

Unix time is a time format not a time reference. It represents the number of milliseconds (or seconds) since 1.1.1970 UTC. Ideally your system time is synchronized with UTC by a TimeServer (NTP).

要转换并获取偏移量,您应该使用固定偏移量:(6.1.1980 UTC - 1.1.1970 UTC)

To convert, and get your offset, you should use a fixed offset: (6.1.1980 UTC - 1.1.1970 UTC)

然后将 GPS 的当前值添加到 UTC 偏差(当前为 16 秒).例如使该值可配置,或从 GPS 设备读取当前偏移量(他们知道 UTC 和 GPS 时间之间的差异)

and THEN add the current value of GPS to UTC deviation (currently 16s). E.g make that value configurable, or read the current offset from a GPS device (they know the difference between UTC and GPS Time)

您所说的不同值是由于将 1970 年到 1980 年的偏移量与闰秒混淆造成的.不要那样做,分开处理.

The different values you stated are caused by mixing up 1970 to 1980 offset with leap seconds. Dont do that, handle them separately.

这个java程序:

SimpleDateFormat df = new SimpleDateFormat();
df.setTimeZone(TimeZone.getTimeZone("UTC"));

Date x = df.parse("1.1.1970 00:00:00");
Date y = df.parse("6.1.1980 00:00:00");

long diff = y.getTime() - x.getTime();
long diffSec = diff / 1000;

System.out.println("diffSec= " + diffSec);

输出这个值:

差异安全= 315964800

diffSec= 315964800

所以这是 GPS 时间开始的 1.1.1970 UTC 和 6.1.1980 UTC 之间的正确偏移量.然后,您必须进一步校正自 1980 年 1 月 6 日和今天引入的 16 秒,以计算当前 UTC 时间的 GPS 时间.

So this is the correct offset between 1.1.1970 UTC and 6.1.1980 UTC where GPS Time began. Then you have to correct further 16 seconds which were introduced since 6.1.1980 and today, to calculate the GPS Time of a current UTC time.

这篇关于Unix 纪元和 GPS 纪元之间的刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆