안녕 나는 문제가 나는이 시도 =>는 GMT 시간을 가져 두 시간 전에 파이썬 2.7
def get_timestamp():
"""Return correctly formatted timestamp"""
return strftime("%Y-%m-%dT%H:%M:%SZ", gmtime())
def two_hours_ago():
"""Return correctly formatted timestamp"""
last = (date.today() - timedelta(hours=1))
return strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()-'2HOURS')
내 get_timestamp에 유사한 기능에서 두 시간 전에 시간을 얻는 데 :
def two_hours_ago():
"""Return correctly formatted timestamp"""
today = date.today()
yesterday = (today - timedelta(hours=2))
print(yesterday.timetuple())
return strftime("%Y-%m-%dT%H:%M:%SZ", yesterday.timetuple())
UPDATE를 감사합니다. Huang Yen Hao
Amazon MWS에 대해 ISO 형식으로 반환 된 2 시간 간격을 찾고 있었지만 다음 함수를 사용하여 올바른 형식의 시간.
def two_hours_ago():
"""Return correctly formatted timestamp"""
now = datetime.now()
two_hours_ago = (now - timedelta(hours=2))
return two_hours_ago.strftime("%Y-%m-%dT%H:%M:%SZ")
def now():
"""Return correctly formatted timestamp"""
now = datetime.now()
two_hours_ago = (now - timedelta(hours=0))
return two_hours_ago.strftime("%Y-%m-%dT%H:%M:%SZ")
앞에'date' 객체를 다음과 같이 수행합니다. 그래서'today - timedelta (시간 = 2)'는 의미가 없습니다. –
UTC 날짜와 시간으로 작업하려면'datetime.datetime.utcnow()'를 사용할 수 있습니다. –
_ 나는 이것을 시도했습니다. 그것은 무엇을했으며, 당신의 기대를 어떻게 충족시키지 못했습니까? –