我试图用 Python 生成一个 RFC 3339 UTC 时间戳:
>>> d = datetime.datetime.now()
>>> print d.isoformat('T')
2011-12-18T20:46:00.392227
我的问题是设置 UTC 偏移量。
根据 医生,类方法 datetime.now([tz])
接受一个可选的 tz
参数,其中 tz must be an instance of a class tzinfo subclass
和 datetime.tzinfo
是 an abstract base class for time zone information objects.
这是我迷失的地方-为什么 tzinfo 是一个抽象类,我应该如何实现它?
(在 PHP 中,注意:和 timestamp = date(DATE_RFC3339);
一样简单,这就是为什么我不能理解为什么 Python 的方法如此复杂...)