How can I parse parse date with time and miliseconds in Python?

435 views Asked by At

I want to convert a datestring into another date format.

The datestring

2014-11-20T00:00:00.000Z

The code

datetime.datetime.strptime(date, '%Y-%m-%dT%H:%M:%S%Z').strftime('%Y%m%d')

The error

time data '2014-11-20T00:00:00.000Z' does not match format '%Y-%m-%dT%H:%M:%S%Z'

I can read the error message but I cannot find the right format that matches the datestring.

1

There are 1 answers

0
Jakob On BEST ANSWER

To include the millisecond paramater use this: datetime.datetime.strptime(d, '%Y-%m-%dT%H:%M:%S.%fZ').strftime('%Y%m%d')