2

我有一个与 Jenkins API (jenkinsapi) 集成的 Django 应用程序。我在 Build 对象上调用 get_timestamp() 方法。在交互模式下,它返回一个日期字符串,如“2013-05-07 09:29:46”;但是,在 Django 中,它返回一个 long,我认为它是一个 Unix 日期时间戳,但它是一个日期,到目前为止,我得到 ValueError: year is out of range。它返回的值是 1368805100576。

>>> b = api.get_jobs()
>>> for job in b:
...     last_build = job[1].get_last_build_or_none()
...     print last_build.id(), last_build.get_timestamp() 
...
3 2013-05-07 09:29:46
2 2013-05-07 09:28:52

并且从非交互模式:

print current_build.get_timestamp()
friendly_timestamp =       datetime.datetime.fromtimestamp(int(current_build.get_timestamp())).strftime('%Y-%m-%d %H:%M:%S')
ValueError: year is out of range

知道为什么这些会有所不同以及 get_timestamp 返回的时间有多长吗?

4

1 回答 1

6

看起来是以毫秒为单位的,

>>> import datetime
>>> datetime.datetime.fromtimestamp(1368805100576/1000)
datetime.datetime(2013, 5, 17, 8, 38, 20)
于 2013-06-04T20:01:52.597 回答