Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import datetime
def convert_to_datetime(date_string):
""" input: %Y-%m-%d %H:%M:%S,%f
example: 2014-01-05 22:20:50,307
return: datetime object
"""
date_format = "%Y-%m-%d %H:%M:%S,%f"
return datetime.datetime.strptime(date_string, date_format)
if __name__ == '__main__':
date_string = "2014-01-05 22:20:50,307"
print("date_string: {0}".format(date_string))
print("convert_to_datetime: {0}".format(convert_to_datetime(date_string)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.