python: how to handle timestamps (ISO8601)

前端 未结 2 1391
臣服心动
臣服心动 2021-01-12 16:28

I have to deal in python with strings representing iso8601 timestamps.

My timestamps string are therefore in the following form:

timestamp = \"2011-0         


        
2条回答
  •  深忆病人
    2021-01-12 16:46

    You'll need to add an external module that provides timezone support; the pytz module provides you with the necessary timezone database.

    You'll either need to parse the timezone by hand to construct a pytz timezone, or use a package like zc.iso8601 or iso8601 to do the parsing for you:

    from zc.iso8601.parse import datetimetz
    datetimetz(timestamp)
    

提交回复
热议问题