こんにちは、私はトラブル私はこの試みた=>はGMT時間を取得する2時間前にはPython 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に同様の機能で2時間前の時間を取得して過ごしています:
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")
を次のように実行します。だから今日のタイムディータ(時= 2)は意味がありません。 –
UTCの日付と時刻を扱う場合は、 'datetime.datetime.utcnow()'を使用できます。 –
_私はこれを試しました。何をしましたか、それはあなたの期待にどうやって満たされませんでしたか? –