【发布时间】:2018-08-21 06:58:36
【问题描述】:
对此还是陌生的。我试图将 13 位时间戳转换为您可以阅读但没有运气的东西。我正在做的是从楼宇自动化系统中采样温度数据。这是我正在使用的代码。我错过了一些非常简单的东西。我可以在正确的方向戳一下吗?
when_updated=driver.find_element_by_name("_lastUpdated")
timestamp=when_updated.get_attribute("value")
print("Timestamp:", timestamp)
nos=10 # Number of samples
freq=5 # Sampling frequency
print("\nTemperature & timestamp, sampled every", freq, "seconds:")
while True:
ts=driver.find_element_by_name("_lastUpdated").get_attribute("value")
print("\nTemperature: ", element.text, "read at:", ts)
time.sleep(freq)
driver.switch_to_default_content()
输出
Temperature:
Timestamp: 0
Temperature & timestamp, sampled every 5 seconds:
Temperature: read at: 0
Temperature: 21.0 ºC read at: 1520912895599
Temperature: 21.0 ºC read at: 1520912901432
Temperature: 21.0 ºC read at: 1520912907070
【问题讨论】:
-
您已经收到了很好的
print电话,可以向您显示用于调试目的的时间戳。为什么不能复制输出并将其粘贴到此处,以便我们查看实际得到的内容? -
无论如何,一个“13 位 UNIX 时间戳”可能是一个 10 位 Unix 时间戳加上 3 个毫秒的数字。如果它看起来非常接近 1520920203506,我'我会更加确定,但遗憾的是我不知道你的 13 位数字是什么。无论如何,如果这是你所拥有的,你需要做的是将
timestamp/1000从datetime传递给你最喜欢的函数模块或第三方库,它应该可以正常工作。(嗯,你可能还需要弄清楚它是 UTC 还是本地时间,但这并不难。)