Created
March 7, 2011 17:09
-
-
Save kisom/858808 to your computer and use it in GitHub Desktop.
get datetime.datetime object from str(datetime.datetime)
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
def get_datetime(timestamp): | |
""" | |
Returns a datetime object from str(datetime.datetime). | |
""" | |
ctor = [] | |
timestamp = timestamp.split() | |
date = [ int(i) for i in timestamp[0].split('-') ] | |
time = [ int(i) for i in timestamp[1].replace('.', ':').split(':') ] | |
ctor.extend(date) | |
ctor.extend(time) | |
return eval('datetime.datetime(%d, %d, %d, %d, %d, %d, %d)' % tuple(ctor)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment