Created
March 12, 2015 18:47
-
-
Save drboyer/3c9dd9f0e271e56dd0f0 to your computer and use it in GitHub Desktop.
I always forget how to create a datetime object from a formatted string in Python 2.4 (or earlier), where the datetime.strptime method doesn't exist. You can easily make it using the time module though...
This file contains 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
# Do imports of these modules somewhere up top | |
import time, datetime | |
# timestring is a string containing the time and/or date you want to parse | |
# format is the time format to parse. | |
# Reference: https://docs.python.org/2.6/library/datetime.html#strftime-and-strptime-behavior | |
mydatetime = datetime.datetime(*(time.strptime(timestring, format)[0:6])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment