Convert timestamps with offset to datetime obj using strptime

前端 未结 4 515

I am trying to convert time-stamps of the format \"2012-07-24T23:14:29-07:00\" to datetime objects in python using strptime method. The problem is with the time offset at t

4条回答
  •  清酒与你
    2020-11-22 04:29

    With python 3.5.2
    To convert 26 Sep 2000 05:11:00 -0700

    from datetime import datetime    
    dt_obj = datetime.strptime("26 Sep 2000 05:11:00 -0700", '%d %b %Y %H:%M:%S %z')
    

    To convert 2012-07-24T23:14:29 -0700

    dt_obj = datetime.strptime('2012-07-24T23:14:29 -0700', '%Y-%m-%dT%H:%M:%S %z')
    

    Python 3.5.2 doesn't support -07:00 time offset ':' should be removed

提交回复
热议问题