Convert unicode to datetime proper strptime format

后端 未结 2 1517
鱼传尺愫
鱼传尺愫 2020-12-30 03:58

I am trying to convert a unicode object to a datetime object.

I read through the documentation: http://docs.python.org/2/library/time.html#time.strptime

and

相关标签:
2条回答
  • 2020-12-30 04:33

    One option is to let dateutil do the job:

    >>> from dateutil import parser
    >>> parser.parse('2014-01-15T01:35:30.314Z')
    datetime.datetime(2014, 1, 15, 1, 35, 30, 314000, tzinfo=tzutc())
    
    0 讨论(0)
  • 2020-12-30 04:36

    You can parse the microseconds:

    from datetime import datetime
    date_posted = '2014-01-15T01:35:30.314Z'
    datetime.strptime(date_posted, '%Y-%m-%dT%H:%M:%S.%fZ')
    
    0 讨论(0)
提交回复
热议问题