我正在尝试向从 json 对象接收的日期戳字符串添加秒数,但我尝试使用的日期时间函数不允许字符串,并且希望将日期分隔为:datetime.strftime(2011,11,18)
. 这是我所拥有的:
import requests
from datetime import datetime
def call():
pay = {'token' : "802ba928cd3ce9acd90595df2853ee2b"}
r = requests.post('http://challenge.code2040.org/api/dating',
params=pay)
response = r.json()
time = response['datestamp']
interval = response['interval']
utc = datetime.strftime(time, '%Y-%m-%dT&H:%M:%S.%fZ')
timestamp = (utc-time).total_seconds()
utc_dt = datetime(time) + timedelta(seconds=timestamp)
print(utc_dt.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
还有另一种方法可以为 ISO8601 日期戳添加时间吗?