简体   繁体   English

如何在python中解码hbase时间戳值?

[英]how to decode hbase timestamp value in python?

I am new to hbase and currently I am using hbase-1.2.6. 我是hbase的新手,目前正在使用hbase-1.2.6。 I did the connection to hbase using python script by using happybase package. 我通过使用happybase包使用python脚本完成了与hbase的连接。 my question is : can someone please let me know how to decode timestamp value which is automatically inserted whenever we put any records in table? 我的问题是:有人可以让我知道如何解码在我们将任何记录放入表中时自动插入的时间戳值吗?

1.what is the exact interpretation of timestamp value in hbase? 
2.can we convert this timestamp value to yy-mm-dd-hh:mm:ss format?

The timestamp value is the number of milliseconds since the epoch (January 1, 1970 UTC). 时间戳值是自该纪元(1970年1月1日UTC)以来的毫秒数。 You can use the python datetime module to manipulate it. 您可以使用python datetime模块进行操作。 Example: 例:

from datetime import datetime as dt
print (dt.fromtimestamp(1511356398000 / 1000))

Output: 
2017-11-22 07:13:18

The result is a datetime object in my local time zone. 结果是我本地时区中的datetime对象。 (Central USA) The datetime.fromtimestamp method wants a floating point value that is the time in seconds since the epoch, so divide the time in milliseconds by 1000. (美国中部) datetime.fromtimestamp方法需要一个浮点值,该浮点值是自该纪元以来的秒数,因此将毫秒数除以1000。

Here is the datetime module reference. datetime模块参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM