하루 전의 RFC 3339 타임스탬프 가져오기
-
21-12-2019 - |
문제
보고 이것 대답 코드에 표시된 것처럼 RFC 3339 기반 시간을 상당히 쉽게 얻을 수 있습니다.
d = datetime.datetime.utcnow() # <-- get time in UTC
print d.isoformat("T") + "Z"
정확히 하루 전의 시간 형식을 어떻게 얻을 수 있는지 궁금합니다.그것은 본질적으로 day-1
, 그러나 이 작업을 수행하는 방법을 잘 모르겠습니다.
해결책
하루 전에 받을 수 있어요 x
와 함께:
x = x + datetime.timedelta(days = -1)
다음 기록은 이를 실제로 보여줍니다.
pax> python
Python 2.7.3 (default, Jan 2 2013, 16:53:07)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> d = datetime.datetime.utcnow()
>>> d
datetime.datetime(2014, 2, 26, 1, 11, 1, 536396)
>>> print d.isoformat("T") + "Z"
2014-02-26T01:11:01.536396Z
>>> d = d + datetime.timedelta(days=-1)
>>> d
datetime.datetime(2014, 2, 25, 1, 11, 1, 536396)
>>> print d.isoformat("T") + "Z"
2014-02-25T01:11:01.536396Z
제휴하지 않습니다 StackOverflow