What possible values does datetime.strptime() accept for %Z?

前端 未结 2 712
臣服心动
臣服心动 2021-01-17 16:20

Python\'s datetime.strptime() is documented as supporting a timezone in the %Z field. So, for example:

In [1]: datetime.strptime(\'2009-08-19 14:20:36 UTC\',         


        
2条回答
  •  庸人自扰
    2021-01-17 16:46

    I gather they are GMT, UTC, and whatever is listed in time.tzname.

    >>> for t in time.tzname:
    ...     print t
    ...
    Eastern Standard Time
    Eastern Daylight Time
    >>> datetime.strptime('2009-08-19 14:20:36 Eastern Standard Time', "%Y-%m-%d %H:%M:%S %Z")
    datetime.datetime(2009, 8, 19, 14, 20, 36)
    >>> datetime.strptime('2009-08-19 14:20:36 UTC', "%Y-%m-%d %H:%M:%S %Z")
    datetime.datetime(2009, 8, 19, 14, 20, 36)
    >>> datetime.strptime('2009-08-19 14:20:36 GMT', "%Y-%m-%d %H:%M:%S %Z")
    datetime.datetime(2009, 8, 19, 14, 20, 36)
    

    These settings are machine-specific, of course, and yours will be different in all likelihood.

提交回复
热议问题