Python的datetime.strptime()被記錄爲在%Z字段支撐時區。因此,舉例來說:不datetime.strptime()接受%Z什麼可能的值?
In [1]: datetime.strptime('2009-08-19 14:20:36 UTC', "%Y-%m-%d %H:%M:%S %Z")
Out[1]: datetime.datetime(2009, 8, 19, 14, 20, 36)
然而,「UTC」似乎是唯一的時區,我可以得到它的支持:
In [2]: datetime.strptime('2009-08-19 14:20:36 EDT', "%Y-%m-%d %H:%M:%S %Z")
ValueError: time data '2009-08-19 14:20:36 EDT' does not match format '%Y-%m-%d %H:%M:%S %Z'
In [3]: datetime.strptime('2009-08-19 14:20:36 America/Phoenix', "%Y-%m-%d %H:%M:%S %Z")
ValueError: time data '2009-08-19 14:20:36 America/Phoenix' does not match format '%Y-%m-%d %H:%M:%S %Z'
In [4]: datetime.strptime('2009-08-19 14:20:36 -0700', "%Y-%m-%d %H:%M:%S %Z")
ValueError: time data '2009-08-19 14:20:36 -0700' does not match format '%Y-%m-%d %H:%M:%S %Z'
是期待它什麼格式%Z?或者,我如何表示UTC以外的時區?