【问题标题】:Convert seconds since 1-1-1999 to UTC date/time in Python在 Python 中将自 1999 年 1 月 1 日以来的秒数转换为 UTC 日期/时间
【发布时间】:2016-11-16 18:38:29
【问题描述】:

我有一个自January 1, 1999 00:00 UTC(不是纪元)以来以秒为单位的时间戳列表。我正在寻找一种将其转换为更标准格式(如YYYY-MM-DD HH:MM:SS UTC)的日期/时间的方法。我不知道该怎么做,因为它不是更常见的“自纪元以来的秒数”格式。

谢谢。

【问题讨论】:

  • 它应该很容易转换为“自纪元以来的秒数”,因为它只是 915177600 秒的恒定偏移量......

标签: python datetime time


【解决方案1】:

用一些简单的 datetime 和 timedelta 东西弄明白了

d0 = datetime(1999,1,1,0,0,0)
dt = timedelta(seconds = time[0])
d  = d0 + dt 

>>> d
datetime.datetime(2016, 8, 19, 13, 28, 55, 317013)

【讨论】:

    【解决方案2】:

    我不太确定您到底需要什么,但我希望这可以帮助您:

    x = datetime.datetime(1999,1,1)
    y=x + datetime.timedelta(0,1256083200.0)
    print('{:%Y-%m-%d %H:%M:%S}'.format(y))
    #print:'2038-10-21 00:00:00'
    

    参考:

    What is the standard way to add N seconds to datetime.time in Python?

    How to convert a Python datetime object to seconds

    How can I create basic timestamps or dates? (Python 3.4)

    【讨论】:

      猜你喜欢
      • 2012-01-19
      • 1970-01-01
      • 2017-01-09
      • 2012-07-06
      • 1970-01-01
      • 2014-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多