Getting the RFC 3339 timestamp for a day ago
看看这个答案,我可以很容易地得到基于RFC 3339的时间,因为它的代码显示:
1 2 | d = datetime.datetime.utcnow() # <-- get time in UTC print d.isoformat("T") +"Z" |
我想知道我将如何获得相同的时间格式,但就在一天前。 它本质上是
您可以在
1 | x = x + datetime.timedelta(days = -1) |
以下成绩单显示了这一点:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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 |