Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

time data '2015-02-10T13:00:00Z' does not match format '%Y-%m-%d %H:%M:%S' [duplicate]

Tags:

python

django

I am getting

time data '2015-02-10T13:00:00Z' does not match format '%Y-%m-%d %H:%M:%S'

I tried:

import datetime
datetime.datetime.strptime('2015-02-10T13:00:00Z', '%Y-%m-%d %H:%M:%S')

and

import time
time.strptime('2015-02-10T13:00:00Z', '%Y-%m-%d %H:%M:%S')

what am I doing wrong?

like image 698
doniyor Avatar asked Mar 17 '23 02:03

doniyor


1 Answers

As a quick workaround, you could add T and Z characters into the datetime formatting:

import datetime            #          v  note  v
datetime.datetime.strptime('2015-02-10T13:00:00Z', '%Y-%m-%dT%H:%M:%SZ')
# datetime.datetime(2015, 2, 10, 13, 0)            #        ^  note  ^

But it's better to use something that is able to parse ISO-formatted date & time. For example, dateutil.parser:

import dateutil.parser
dateutil.parser.parse('2015-02-10T13:00:00Z')
# datetime.datetime(2015, 2, 10, 13, 0, tzinfo=tzutc())
like image 114
Igor Hatarist Avatar answered Apr 06 '23 04:04

Igor Hatarist