Convert UTC time to python datetime

前端 未结 2 1383
耶瑟儿~
耶瑟儿~ 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 22:58

    Change the year marker in your time format string to %Y:

    time = '2012-03-01T00:05:55+00:00'
    datetime.strptime(time, "%Y-%m-%dT%H:%M:%S+00:00")
    # => datetime.datetime(2012, 3, 1, 0, 5, 55)
    

    See strftime() and strptime() behavior.

提交回复
热议问题