How do I parse an ISO 8601-formatted date?

后端 未结 27 2379
小鲜肉
小鲜肉 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:18

    For something that works with the 2.X standard library try:

    calendar.timegm(time.strptime(date.split(".")[0]+"UTC", "%Y-%m-%dT%H:%M:%S%Z"))
    

    calendar.timegm is the missing gm version of time.mktime.

提交回复
热议问题