Python parsing date with strptime

后端 未结 2 522
再見小時候
再見小時候 2021-01-20 11:36

I have url that returns date in this format

url_date = \"2015-01-12T08:43:02Z\"

I don\'t know why there are strings, it would have been sim

2条回答
  •  攒了一身酷
    2021-01-20 12:11

    You were getting close with the "Z" in your final attempt - you need to specify the T, Z, and colon literal values in your format string.

    >>> import datetime
    >>> url_date = "2015-01-12T08:43:02Z"
    >>> datetime.datetime.strptime(url_date , '%Y-%m-%dT%H:%M:%SZ')
    datetime.datetime(2015, 1, 12, 8, 43, 2)
    

提交回复
热议问题