【问题标题】:Sqlite3 data convert to python for real timeSqlite3数据实时转换为python
【发布时间】:2012-04-18 13:19:57
【问题描述】:

我从sqlite3读取数据,我需要使用'last_visit_time',但是数据是'12979085322912388L',我只是使用python

import datetime,time
Traceback (most recent call last):
  File "t1.py", line 21, in <module>
    print time.gmtime(long(12979085330693664L))
ValueError: timestamp out of range for platform time_t

..ctime,gmtime....不能用,范围限制,怎么翻译成实时,非常感谢!!

【问题讨论】:

    标签: python sqlite datetime time


    【解决方案1】:
    >>> from datetime import datetime
    >>> datetime.utcfromtimestamp(1297908532.2912388)
    datetime.datetime(2011, 2, 17, 2, 8, 52, 291239)
    

    如果last_visit_time对应2011-02-17,则可以使用

    >>> from datetime import datetime
    >>> datetime.utcfromtimestamp(last_visit_time / 1e7)
    datetime.datetime(2011, 2, 17, 2, 8, 52, 291239)
    

    【讨论】:

    • 但是我不知道last_visit_time,所以是否可以在没有其他信息的情况下提取时间形式12979085330693664L?
    • 如果你没有进一步的信息,你必须猜测。但我认为没有很多其他选择。数据库中有更多的时间戳信息吗?如果您使用我的方法转换其他时间戳,您会得到合乎逻辑的结果吗? (例如不比网站年龄大,不比现在新等)
    • 12979231706879288L 最新的时间戳,刚刚,然后 12979231436918790L 可能两分钟前,但我不能客....帮帮我
    猜你喜欢
    • 2015-07-29
    • 2012-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-22
    • 2019-06-22
    • 2012-02-19
    • 1970-01-01
    相关资源
    最近更新 更多