Created
April 27, 2015 16:24
-
-
Save aviafelix/39f32c5728c80acc38bb to your computer and use it in GitHub Desktop.
Python datetime / dateutil parsing dates example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import dateutil.parser | |
timestring1 = '2007-03-04T21:08:12.127' | |
timestring2 = '2012-03-04 12:08:12.354' | |
dt1 = datetime.datetime.strptime(timestring1, '%Y-%m-%dT%H:%M:%S.%f') | |
dt2 = datetime.datetime.strptime(timestring2, '%Y-%m-%d %H:%M:%S.%f') | |
dup1 = dateutil.parser.parse(timestring1) | |
dup2 = dateutil.parser.parse(timestring2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An example format for strings with timezones:
"%Y-%m-%dT%H:%M:%S.%f%z"
.But anyway it's better to use dateutil.parser.