第一种用pytz
第二种手动加时区再转换格式
a = datetime.datetime.today()
o = datetime.timedelta(hours=8)
(a+o).strftime("%Y-%m-%d_%H:%M")
转化后效果 test_admin_stable_2016-04-18_21:21.tar.gz
如果你的程序要考虑时区,可以使用pytz。datetime模块中有tzinfo相关的东西,但是它是一个抽象类,文档上说:
tzinfo is an abstract base clase, meaning that this class should not be instantiated directly. You need to derive a concrete subclass, and (at least) supply implementations of the standard tzinfo methods needed by thedatetime methods you use. The datetime module does not supply any concrete subclasses of tzinfo.
上面是说tzinfo是一个抽象类,不应该被直接实例化。你需要派生子类,提供相应的标准方法。datetime模块并不提供tzinfo的任何子类。