This question already has an answer here:
I have a datasets where all the dates have the following format:
2012-10-09T19:00:55Z
I'd like to be able to be able to use methods like .weekday
on them. How do I convert them to the proper format in Python?
You can use
dateutil.parser.parse
to parse strings into datetime objects.dateutil.parser.parse
will attempt to guess the format of your string, if you know the exact format in advance then you can usedatetime.strptime
which you supply a format string to (see Brent Washburne's answer).This has already been answered here: How do I translate a ISO 8601 datetime string into a Python datetime object?
You should have a look at
moment
which is a python port of the excellent js libmomentjs
.One advantage of it is the support of
ISO 8601
strings formats, as well as a generic "% format" :Result: