Convert UTC time to python datetime

前端 未结 2 1344
耶瑟儿~
耶瑟儿~ 2021-01-14 22:33

I have numerous UTC time stamps in the following format: 2012-04-30T23:08:56+00:00 I want to convert them to python datetime objects but am having trouble.

2条回答
  •  一生所求
    2021-01-14 23:12

    I highly recommend python-dateutil library, it allows conversion of multiple datetime formats from raw strings into datetime objects with/without timezone set

    >>> from dateutil.parser import parse
    >>> parse('2012-04-30T23:08:56+00:00')
    
    datetime.datetime(2012, 4, 30, 23, 8, 56, tzinfo=tzutc())
    

提交回复
热议问题