How do you convert YYYY-MM-DDTHH:mm:ss.000Z time format to MM/DD/YYYY time format in Python?

前端 未结 5 907
感动是毒
感动是毒 2020-12-08 06:43

For example, I\'m trying to convert 2008-09-26T01:51:42.000Z to 09/26/2008. What\'s the simplest way of accomplishing this?

5条回答
  •  囚心锁ツ
    2020-12-08 07:31

    I know this is really old question, but you can do it with python datetime.strptime()

    >>> from datetime import datetime
    >>> date_format = "%Y-%m-%dT%H:%M:%S.%fZ" 
    >>> datetime.strptime('2008-09-26T01:51:42.000Z', date_format)
    datetime.datetime(2008, 9, 26, 1, 51, 42)
    

提交回复
热议问题