本文介绍了从2000年1月1日开始从UNIX时间转换为时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试与使用时间戳记的API进行交互,该时间戳记的起始时间与UNIX时期不同。它似乎开始于2000年1月1日开始计数,但是我不确定确切如何进行转换或该日期时间格式的名称。

I am trying to interact with an API that uses a timestamp that starts at a different time than UNIX epoch. It appears to start counting on 2000-01-01, but I'm not sure exactly how to do the conversion or what the name of this datetime format is.

何时我在1456979510上发送了一条消息,并在510294713处收到了答复。

两者之间的差是946684796(有时是94668479 7 )秒,大约是30秒

When I send a message at 1456979510 I get a response back saying it was received at 510294713.
The difference between the two is 946684796 (sometimes 946684797) seconds, which is approximately 30 years.

有人可以让我知道在两者之间进行转换的正确方法吗?还是我可以直接在Python中生成它们?

Can anyone let me know the proper way to convert between the two? Or whether I can generate them outright in Python?

谢谢

编辑

我应该提到的其他细节是,这是Zigbee设备的API。我在他们的文档中找到了以下数据类型条目:

An additional detail I should have mentioned is that this is an API to a Zigbee device. I found the following datatype entry in their documentation:

我仍然不确定最简单的方法

I'm still not sure the easiest way to convert between the two

推荐答案

时间 1970年1月1日00:00:00 被认为是 UNIX时代。因此,如果要从UNIX时间转换为具有2000年1月1日(例如2000年)的时间戳,最简单的方法是从UNIX时间中减去2000年1月1日的UNIX时间。 / p>

The time 1 January 1970 00:00:00 is considered the UNIX epoch. So, if you want to convert from UNIX time to a timestamp having an epoch of January 1, 2000 (Let's say, 2000 epoch) the simplest way would be to simply subtract the UNIX time of January 1, 2000 from the UNIX time.

<2000 time> = <UNIX time> - <January 1, 2000 UNIX time>

<UNIX time> = <2000 time> + <January 1, 2000 UNIX time>

2000年1月1日的UNIX时间为 946684800

Where January 1, 2000 UNIX time is 946684800.

编辑:文档确实说

因此, 946684800 确切的时差,该值应用于计算。您计算出的几秒钟差异可能归因于网络延迟或其他一些延迟。

So, 946684800 is the exact time difference which should be used to calculate. The few seconds difference that you calculated could be attributed to network delay or some other delays.

这篇关于从2000年1月1日开始从UNIX时间转换为时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 19:39