How do I parse an ISO 8601-formatted date?

后端 未结 27 3029
小鲜肉
小鲜肉 2020-11-21 06:08

I need to parse RFC 3339 strings like \"2008-09-03T20:56:35.450686Z\" into Python\'s datetime type.

I have found strptime in the Python sta

27条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-21 06:31

    I have found ciso8601 to be the fastest way to parse ISO 8601 timestamps. As the name suggests, it is implemented in C.

    import ciso8601
    ciso8601.parse_datetime('2014-01-09T21:48:00.921000+05:30')
    

    The GitHub Repo README shows their >10x speedup versus all of the other libraries listed in the other answers.

    My personal project involved a lot of ISO 8601 parsing. It was nice to be able to just switch the call and go 10x faster. :)

    Edit: I have since become a maintainer of ciso8601. It's now faster than ever!

提交回复
热议问题